Skip to content

Commit b31fb07

Browse files
PJColomboluis-herasme
authored andcommitted
perf: decouple item counting logic from data fetching (#581)
* fix(api): set category filter to `ROLLUP` when the rollup filter is provided * feat(api): create blob `getCount` procedure * chore: add changeset * refactor(web): use `getCount()` procedure to retrieve total amount of blobs * chore: add changeset * feat(api): create block `getCount` procedure * chore: add changeset * fix(web): align header sleketon on blobs page view * refactor(web): use `getCount()` procedure to retrieve total amount of blocks * refactor(api): use count logic in `getAll` block procedure * feat(api): add transaction `getCount` procedure * refactor(web): use `getCount()` procedure to retrieve total amount of transactions on txs page * chore: merge changesets * refactor(web): organize query parameters by filter and pagination usage * test(api): remove rollup test
1 parent 95583dd commit b31fb07

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

.changeset/chilly-rings-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@blobscan/web": patch
3+
---
4+
5+
Improved performance on Blobs, Blocks and Txs pages by fetching the total amount of items only once and not on every request

.changeset/tame-rabbits-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@blobscan/api": minor
3+
---
4+
5+
Added procedures to count total amount of blobs, blocks or txs given a set of filters

packages/api/src/routers/blob/getAll.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Prisma } from "@blobscan/db";
21
import { z } from "@blobscan/zod";
32

43
import {
@@ -45,16 +44,6 @@ export const getAll = publicProcedure
4544
.use(withExpands)
4645
.output(outputSchema)
4746
.query(async ({ ctx: { filters, expands, pagination, prisma, count } }) => {
48-
let leadingOrderColumn: Prisma.BlobsOnTransactionsOrderByWithRelationInput =
49-
{
50-
blockTimestamp: filters.sort,
51-
};
52-
53-
if (filters.blockNumber) {
54-
leadingOrderColumn = {
55-
blockNumber: filters.sort,
56-
};
57-
}
5847
const blockFiltersExists = filters.blockSlot || filters.blockType;
5948
const txFiltersExists =
6049
filters.transactionRollup !== undefined ||

packages/api/src/routers/blob/getCount.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ export async function countBlobs(
2424
select: {
2525
totalBlobs: true,
2626
},
27-
where: {
28-
AND: [{ category: null }, { rollup: null }],
29-
},
3027
});
3128

3229
return overallStats?.totalBlobs ?? 0;

packages/api/src/routers/tx/getCount.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ export async function countTxs(prisma: BlobscanPrismaClient, filters: Filters) {
2121
select: {
2222
totalTransactions: true,
2323
},
24-
where: {
25-
AND: [{ category: null }, { rollup: null }],
26-
},
2724
});
2825

2926
return overallStats?.totalTransactions ?? 0;

packages/api/test/blob.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ describe("Blob router", async () => {
129129

130130
describe("getCount", () => {
131131
it("should return the overall total blobs stat when no filters are provided", async () => {
132-
await ctx.prisma.blobOverallStats.populate();
132+
await ctx.prisma.blobOverallStats.increment({
133+
from: 0,
134+
to: 9999,
135+
});
133136
const { totalBlobs } = await caller.blob.getCount({});
134137

135138
expect(totalBlobs).toBe(fixtures.canonicalBlobs.length);

packages/api/test/block.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ describe("Block router", async () => {
134134

135135
describe("getCount", () => {
136136
it("should return the overall total blocks stat when no filters are provided", async () => {
137-
await ctx.prisma.blockOverallStats.populate();
137+
await ctx.prisma.blockOverallStats.increment({
138+
from: 0,
139+
to: 9999,
140+
});
138141
const { totalBlocks } = await caller.block.getCount({});
139142

140143
expect(totalBlocks).toBe(fixtures.canonicalBlocks.length);

packages/api/test/tx.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ describe("Transaction router", async () => {
9595

9696
describe("getCount", () => {
9797
it("should return the overall total transactions stat when no filters are provided", async () => {
98-
await ctx.prisma.transactionOverallStats.populate();
99-
98+
await ctx.prisma.transactionOverallStats.increment({
99+
from: 0,
100+
to: 9999,
101+
});
100102
const { totalTransactions } = await caller.tx.getCount({});
101103

102104
expect(totalTransactions).toBe(fixtures.canonicalTxs.length);

0 commit comments

Comments
 (0)