A decentralized music tracking and discovery platform built on AT Protocol 🎵

fix: improve existing scrobble check by allowing a 5-second window for timestamp comparison

+10 -2
+10 -2
apps/api/src/nowplaying/nowplaying.service.ts
··· 368 368 userDid: string 369 369 ): Promise<void> { 370 370 // check if scrobble already exists (user did + timestamp) 371 + const scrobbleTime = dayjs.unix(track.timestamp); 371 372 if (track.timestamp) { 372 373 const existingScrobble = await ctx.client.db.scrobbles 374 + .filter("user_id.did", equals(userDid)) 373 375 .filter({ 374 - "user_id.did": userDid, 375 - timestamp: dayjs.unix(track.timestamp).toISOString(), 376 + $any: [ 377 + { 378 + timestamp: { 379 + $ge: scrobbleTime.subtract(5, "seconds").toISOString(), 380 + }, 381 + }, 382 + { timestamp: { $le: scrobbleTime.add(5, "seconds").toISOString() } }, 383 + ], 376 384 }) 377 385 .getFirst(); 378 386