Skip to content

Commit

Permalink
progress on ALT service query performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Sep 22, 2024
1 parent 73c6f43 commit 757eb9f
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 150 deletions.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencyResolutionManagement {
}
versionCatalogs {
libs {
from("software.sava:solana-version-catalog:0.1.23")
from("software.sava:solana-version-catalog:0.1.26")
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,39 @@
import software.sava.rpc.json.http.response.AccountInfo;
import software.sava.services.core.remote.call.Call;

import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;

class LookupTableCallHandler implements Function<List<AccountInfo<AddressLookupTable>>, IndexedTable[]> {
class LookupTableCallHandler implements Function<List<AccountInfo<AddressLookupTable>>, AddressLookupTable[]> {

private static final Function<AccountInfo<AddressLookupTable>, AddressLookupTable> GET_TABLE = AccountInfo::data;
private static final Predicate<AddressLookupTable> IS_ACTIVE = AddressLookupTable::isActive;
private static final Comparator<AddressLookupTable> BY_NUM_TABLES = (a, b) -> Integer.compare(b.numAccounts(), a.numAccounts());
private static final IntFunction<AddressLookupTable[]> ARRAY_GENERATOR = AddressLookupTable[]::new;

protected final ExecutorService executorService;
protected final Call<List<AccountInfo<AddressLookupTable>>> call;
protected final Predicate<AddressLookupTable> filter;
private final ExecutorService executorService;
private final Call<List<AccountInfo<AddressLookupTable>>> call;
private final Predicate<AddressLookupTable> filter;

LookupTableCallHandler(final ExecutorService executorService,
final Call<List<AccountInfo<AddressLookupTable>>> call,
final Predicate<AddressLookupTable> minAccountsFilter) {
final Predicate<AddressLookupTable> minAccountsFilter,
final TableStats tableStats) {
this.executorService = executorService;
this.call = call;
this.filter = IS_ACTIVE.and(minAccountsFilter);
this.filter = IS_ACTIVE.and(minAccountsFilter).and(tableStats::addAccountSet);
}

@Override
public IndexedTable[] apply(final List<AccountInfo<AddressLookupTable>> accountInfos) {
final var filteredAndSorted = accountInfos.stream()
.map(GET_TABLE)
public AddressLookupTable[] apply(final List<AccountInfo<AddressLookupTable>> accountInfos) {
return accountInfos.stream()
.map(AccountInfo::data)
.filter(filter)
.sorted(BY_NUM_TABLES)
.toArray(ARRAY_GENERATOR);
final var indexed = new IndexedTable[filteredAndSorted.length];
for (int i = 0; i < indexed.length; ++i) {
indexed[i] = new IndexedTable(i, filteredAndSorted[i].withReverseLookup());
}
return indexed;
.sorted((a, b) -> Integer.compare(b.numUniqueAccounts(), a.numUniqueAccounts()))
.toArray(AddressLookupTable[]::new);
}


CompletableFuture<IndexedTable[]> callAndApply() {
CompletableFuture<AddressLookupTable[]> callAndApply() {
return call.async(executorService).thenApply(this);
}
}
Loading

0 comments on commit 757eb9f

Please sign in to comment.