Skip to content

Commit

Permalink
more predictable ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Nov 30, 2023
1 parent 4ffd60b commit 99b0d04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/store-indexer/src/postgres/getLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ export async function getLogs(
.select()
.from(tables.recordsTable)
.where(or(...conditions))
.orderBy(asc(tables.recordsTable.lastUpdatedBlockNumber));
.orderBy(
asc(tables.recordsTable.lastUpdatedBlockNumber),
// TODO: add logIndex and use that to sort instead of address/tableId?
asc(tables.recordsTable.address),
asc(tables.recordsTable.tableId)
);

const blockNumber = records.reduce(
(max, record) => bigIntMax(max, record.lastUpdatedBlockNumber ?? 0n),
Expand Down
4 changes: 3 additions & 1 deletion packages/store-sync/src/sqlite/getTables.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
import { inArray } from "drizzle-orm";
import { asc, inArray } from "drizzle-orm";
import { Table } from "../common";
import { getTableName } from "./getTableName";
import { mudStoreTables } from "./internalTables";
Expand All @@ -15,6 +15,8 @@ export function getTables(
.select()
.from(mudStoreTables)
.where(ids.length ? inArray(mudStoreTables.id, ids) : undefined)
// TODO: add logIndex and use that to sort instead of address/tableId?
.orderBy(asc(mudStoreTables.lastUpdatedBlockNumber), asc(mudStoreTables.address), asc(mudStoreTables.tableId))
.all();

return tables;
Expand Down

0 comments on commit 99b0d04

Please sign in to comment.