Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion analytics/src/bucketed-trending.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ describe("bucketed trending", () => {
await store.getTop("posts", 10, Date.parse("2026-01-01T01:00:00.000Z")).catch(() => undefined);
expect(first.redis.zunionstore).toHaveBeenCalledOnce();
const args = (first.redis.zunionstore as ReturnType<typeof vi.fn>).mock.calls[0] as unknown[];
// dest + numkeys + 12*(key+weight) + AGGREGATE + SUM
// dest + numkeys + 12 keys + WEIGHTS + 12 weights + AGGREGATE + SUM
expect(args[1]).toBe(12);
expect(args[14]).toBe("WEIGHTS");
expect(args[27]).toBe("AGGREGATE");
expect(args[28]).toBe("SUM");
expect(second.zsets.size).toBe(0);
});

Expand Down
19 changes: 15 additions & 4 deletions analytics/src/bucketed-trending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,25 @@ export class BucketedTrendingStore {
const prevBuckets = [3, 4, 5, 6, 7, 8, 9, 10, 11].map((d) => current - d);
const tempKey = `trending:tmp:${entityType}:${current}:${Date.now() % 100000}`;
try {
const args: (string | number)[] = [tempKey, recentBuckets.length + prevBuckets.length];
const keys: string[] = [];
const weights: number[] = [];
for (const b of recentBuckets) {
args.push(bucketKey(entityType, b), 1);
keys.push(bucketKey(entityType, b));
weights.push(1);
}
for (const b of prevBuckets) {
args.push(bucketKey(entityType, b), 0.5);
keys.push(bucketKey(entityType, b));
weights.push(0.5);
}
args.push("AGGREGATE", "SUM");
const args: (string | number)[] = [
tempKey,
keys.length,
...keys,
"WEIGHTS",
...weights,
"AGGREGATE",
"SUM"
];
// ZUNIONSTORE with missing keys treats them as empty — safe for cold start.
await (this.redis.zunionstore as (...a: unknown[]) => Promise<number>)(...args);
await this.redis.expire(tempKey, 60);
Expand Down
2 changes: 1 addition & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<url />
</scm>
<properties>
<java.version>25</java.version>
<java.version>21</java.version>
<aws-sdk.version>2.48.3</aws-sdk.version>
<bucket4j.version>8.14.0</bucket4j.version>
<testcontainers.version>1.21.3</testcontainers.version>
Expand Down
Loading