Skip to content

Commit

Permalink
make indexer dumber
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Sep 29, 2023
1 parent 72033de commit 941c863
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
4 changes: 1 addition & 3 deletions packages/store-indexer/src/postgres/createQueryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { buildTable, buildInternalTables, getTables } from "@latticexyz/store-sy
import { QueryAdapter } from "@latticexyz/store-sync/trpc-indexer";
import { debug } from "../debug";
import { getAddress } from "viem";
import { internalTableIds } from "@latticexyz/store-sync";

/**
* Creates a query adapter for the tRPC server/client to query data from Postgres.
Expand All @@ -15,10 +14,9 @@ import { internalTableIds } from "@latticexyz/store-sync";
export async function createQueryAdapter(database: PgDatabase<any>): Promise<QueryAdapter> {
const adapter: QueryAdapter = {
async findAll({ chainId, address, tableIds = [] }) {
const includedTableIds = new Set(tableIds.length ? [...internalTableIds, ...tableIds] : []);
const tables = (await getTables(database))
.filter((table) => address == null || getAddress(address) === getAddress(table.address))
.filter((table) => !includedTableIds.size || includedTableIds.has(table.tableId));
.filter((table) => !tableIds.length || tableIds.includes(table.tableId));

const tablesWithRecords = await Promise.all(
tables.map(async (table) => {
Expand Down
4 changes: 1 addition & 3 deletions packages/store-indexer/src/sqlite/createQueryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { buildTable, chainState, getTables } from "@latticexyz/store-sync/sqlite
import { QueryAdapter } from "@latticexyz/store-sync/trpc-indexer";
import { debug } from "../debug";
import { getAddress } from "viem";
import { internalTableIds } from "@latticexyz/store-sync";

/**
* Creates a storage adapter for the tRPC server/client to query data from SQLite.
Expand All @@ -15,10 +14,9 @@ import { internalTableIds } from "@latticexyz/store-sync";
export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", any>): Promise<QueryAdapter> {
const adapter: QueryAdapter = {
async findAll({ chainId, address, tableIds = [] }) {
const includedTableIds = new Set(tableIds.length ? [...internalTableIds, ...tableIds] : []);
const tables = getTables(database)
.filter((table) => address == null || getAddress(address) === getAddress(table.address))
.filter((table) => !includedTableIds.size || includedTableIds.has(table.tableId));
.filter((table) => !tableIds.length || tableIds.includes(table.tableId));

const tablesWithRecords = tables.map((table) => {
const sqliteTable = buildTable(table);
Expand Down

0 comments on commit 941c863

Please sign in to comment.