Skip to content

Commit

Permalink
⚡️ Simplify unique wallets query
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Nov 8, 2024
1 parent 93e2ea6 commit 4d50dfe
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions packages/ponder/src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ ponder.get("/admin/:wallet/campaignsStats", async (ctx) => {
Campaign,
ReferralCampaignStats,
InteractionEvent,
Product,
ProductInteractionContract,
} = ctx.tables;

Expand Down Expand Up @@ -139,20 +138,16 @@ ponder.get("/admin/:wallet/campaignsStats", async (ctx) => {
// Get the total number of unique users per product
const totalPerProducts = await ctx.db
.select({
productId: Product.id,
productId: ProductInteractionContract.productId,
wallets: countDistinct(InteractionEvent.user),
})
.from(InteractionEvent)
.innerJoin(
ProductInteractionContract,
eq(InteractionEvent.interactionId, ProductInteractionContract.id)
)
.innerJoin(
Product,
eq(ProductInteractionContract.productId, Product.id)
)
.where(inArray(Product.id, uniqueProductIds))
.groupBy(Product.id);
.where(inArray(ProductInteractionContract.productId, uniqueProductIds))
.groupBy(ProductInteractionContract.productId);

// Return the result as json
return ctx.json({
Expand Down

0 comments on commit 4d50dfe

Please sign in to comment.