mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
fix: slow query taking up 66% of db time (#298)
Query was scanning the full index on listen table, when we really only need data from the last hour
This commit is contained in:
parent
7f5328e538
commit
625db7dbe7
1 changed files with 5 additions and 0 deletions
|
|
@ -42,6 +42,10 @@ export class SpotifyService {
|
||||||
private readonly spotifyAuth: SpotifyAuthService,
|
private readonly spotifyAuth: SpotifyAuthService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of users that should be crawled for new listens.
|
||||||
|
* Only returns the lastListen date if it was within the last hour.
|
||||||
|
*/
|
||||||
@Span()
|
@Span()
|
||||||
async getCrawlableUserInfo(): Promise<
|
async getCrawlableUserInfo(): Promise<
|
||||||
{ userID: string; lastListen: Date }[]
|
{ userID: string; lastListen: Date }[]
|
||||||
|
|
@ -57,6 +61,7 @@ export class SpotifyService {
|
||||||
.select(`listen."userId"`)
|
.select(`listen."userId"`)
|
||||||
.addSelect(`listen."playedAt"`)
|
.addSelect(`listen."playedAt"`)
|
||||||
.from("listen", "listen")
|
.from("listen", "listen")
|
||||||
|
.where(`listen."playedAt" > now() - interval '1 hour'`)
|
||||||
.orderBy("listen.userId", "DESC")
|
.orderBy("listen.userId", "DESC")
|
||||||
.addOrderBy("listen.playedAt", "DESC"),
|
.addOrderBy("listen.playedAt", "DESC"),
|
||||||
"listen",
|
"listen",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue