mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
feat(top): implement fallback to global tracks
This commit is contained in:
1 parent
bdee46b7f2
commit
d78af55f10
10 files changed
+62
-15
No files matched your search
@@ -292,7 +292,19 @@ class GuildStatsManager {
|
||||
params = [guildId, lim];
|
||||
}
|
||||
|
||||
const [rows] = await this._pool.execute(sql, params);
|
||||
let [rows] = await this._pool.execute(sql, params);
|
||||
if ((!rows || rows.length === 0) && (timeframe === "month" || timeframe === "week")) {
|
||||
const [allRows] = await this._pool.execute(`
|
||||
SELECT \`title\`, \`artist\`, \`play_count\` as count, \`duration_ms\` as durationMs
|
||||
FROM \`guild_song_counts\`
|
||||
WHERE \`guild_id\` = ?
|
||||
ORDER BY count DESC
|
||||
LIMIT ?;
|
||||
`, [guildId, lim]);
|
||||
if (allRows && allRows.length > 0) {
|
||||
rows = allRows;
|
||||
}
|
||||
}
|
||||
if (rows && rows.length > 0) {
|
||||
const artistMap = {};
|
||||
const tracks = rows.map((r) => {
|
||||
@@ -347,10 +359,20 @@ class GuildStatsManager {
|
||||
}
|
||||
}
|
||||
|
||||
const tracks = Object.values(trackMap)
|
||||
let tracks = Object.values(trackMap)
|
||||
.sort((a, b) => b.count - a.count)
|
||||
.slice(0, lim);
|
||||
|
||||
if (tracks.length === 0 && Object.keys(data.songs || {}).length > 0) {
|
||||
trackMap = data.songs;
|
||||
for (const item of Object.values(trackMap)) {
|
||||
artistMap[item.artist] = (artistMap[item.artist] || 0) + item.count;
|
||||
}
|
||||
tracks = Object.values(trackMap)
|
||||
.sort((a, b) => b.count - a.count)
|
||||
.slice(0, lim);
|
||||
}
|
||||
|
||||
let topArtist = null;
|
||||
const sortedArtists = Object.entries(artistMap).sort((a, b) => b[1] - a[1]);
|
||||
if (sortedArtists.length > 0 && sortedArtists[0][0] !== "Unknown Artist") {
|
||||
|
||||
Reference in new issue
Block a user