Skip to content

Commit

Permalink
storage/mariadb: optimize FavoritesOfDatabase query
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Jun 20, 2024
1 parent c10b1d3 commit bacf591
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions storage/mariadb/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,22 +512,35 @@ LIMIT ? OFFSET ?;
`)

var songFavoritesOfDatabaseOnlyQuery = expand(`
SELECT
{songColumns},
{trackColumns},
{lastplayedSelect},
NOW() AS synctime
WITH
esong
AS (SELECT DISTINCT
esong.*
FROM
enick
JOIN
efave ON efave.inick = enick.id
JOIN
esong ON esong.id = efave.isong
JOIN
tracks ON tracks.hash = esong.hash_link
WHERE
enick.nick = ?
ORDER BY efave.id ASC;
enick.nick = ?)
SELECT
{songColumns},
{trackColumns},
COALESCE(eplay.dt, TIMESTAMP('0000-00-00 00:00:00')) AS lastplayed,
NOW() AS synctime
FROM
tracks
JOIN
esong ON tracks.hash = esong.hash
JOIN
(SELECT
MAX(dt) AS dt,
isong
FROM
eplay
GROUP BY
isong) AS eplay ON eplay.isong = esong.id;
`)

var songFavoritesOfCountQuery = `
Expand Down

0 comments on commit bacf591

Please sign in to comment.