Fixed playback history window
Build and Publish / Build and Publish Docker Image (push) Successful in 5m20s

This commit is contained in:
Ultradesu
2026-07-27 23:41:29 +01:00
parent 134f89fc9d
commit 122214a896
5 changed files with 75 additions and 12 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "furumusic" name = "furumusic"
version = "0.9.4" version = "0.9.5"
edition = "2024" edition = "2024"
description = "Reusable web-app boilerplate: auth, OIDC/SSO, admin panel, user management, i18n, PostgreSQL" description = "Reusable web-app boilerplate: auth, OIDC/SSO, admin panel, user management, i18n, PostgreSQL"
+43
View File
@@ -2434,6 +2434,48 @@ pub mod db_migrations {
&[Operation::custom(create_synced_listen_history).build()]; &[Operation::custom(create_synced_listen_history).build()];
} }
#[cot::db::migrations::migration_op]
async fn repair_legacy_listen_qualification(
ctx: migrations::MigrationContext<'_>,
) -> cot::db::Result<()> {
ctx.db
.raw(
"UPDATE furumusic__listen_event le
SET qualified = (
ph.completed
OR (
COALESCE(ph.duration_listened, 0) >= 5
AND COALESCE(t.duration_seconds, 0) > 0
AND COALESCE(ph.duration_listened, 0) >= LEAST(
COALESCE(t.duration_seconds, 0) / 2.0,
240.0
)
)
)
FROM furumusic__play_history ph
JOIN furumusic__track t ON t.id = ph.track_id
WHERE le.user_id = ph.user_id
AND le.listen_id = 'legacy-web:' || ph.id::text",
)
.await?;
Ok(())
}
#[derive(Debug, Copy, Clone)]
pub struct M0042RepairLegacyListenQualification;
impl migrations::Migration for M0042RepairLegacyListenQualification {
const APP_NAME: &'static str = "furumusic";
const MIGRATION_NAME: &'static str = "m_0042_repair_legacy_listen_qualification";
const DEPENDENCIES: &'static [migrations::MigrationDependency] =
&[migrations::MigrationDependency::migration(
"furumusic",
"m_0041_create_synced_listen_history",
)];
const OPERATIONS: &'static [Operation] =
&[Operation::custom(repair_legacy_listen_qualification).build()];
}
pub const MIGRATIONS: &[&SyncDynMigration] = &[ pub const MIGRATIONS: &[&SyncDynMigration] = &[
&M0006CreateMediaFile, &M0006CreateMediaFile,
&M0007CreateArtist, &M0007CreateArtist,
@@ -2466,5 +2508,6 @@ pub mod db_migrations {
&M0039EnsureFederationContentIdCache, &M0039EnsureFederationContentIdCache,
&M0040CreateContentAddressedMusicRefs, &M0040CreateContentAddressedMusicRefs,
&M0041CreateSyncedListenHistory, &M0041CreateSyncedListenHistory,
&M0042RepairLegacyListenQualification,
]; ];
} }
+16 -9
View File
@@ -1259,15 +1259,19 @@ async fn me_handler(
.await .await
.map_err(|e| cot::Error::internal(e.to_string()))?; .map_err(|e| cot::Error::internal(e.to_string()))?;
let plays: (i64,) = let plays: (i64,) = sqlx::query_as(
sqlx::query_as("SELECT COUNT(*) FROM furumusic__play_history WHERE user_id = $1") "SELECT COUNT(*) FROM furumusic__listen_event
.bind(user.id) WHERE user_id = $1 AND qualified = true",
.fetch_one(pool) )
.await .bind(user.id)
.map_err(|e| cot::Error::internal(e.to_string()))?; .fetch_one(pool)
.await
.map_err(|e| cot::Error::internal(e.to_string()))?;
let listened_seconds: Option<i64> = sqlx::query_scalar( let listened_seconds: Option<i64> = sqlx::query_scalar(
"SELECT COALESCE(SUM(duration_listened), 0) FROM furumusic__play_history WHERE user_id = $1", "SELECT COALESCE(SUM(listened_ms), 0) / 1000
FROM furumusic__listen_event
WHERE user_id = $1 AND qualified = true",
) )
.bind(user.id) .bind(user.id)
.fetch_one(pool) .fetch_one(pool)
@@ -5573,7 +5577,8 @@ async fn history_list_handler(
.map_err(|e| cot::Error::internal(e.to_string()))?; .map_err(|e| cot::Error::internal(e.to_string()))?;
let rows = sqlx::query( let rows = sqlx::query(
"SELECT le.listen_id, le.content_id, le.local_track_id, "SELECT le.listen_id, le.content_id,
COALESCE(le.local_track_id, tr.local_track_id) AS local_track_id,
le.origin_device_id, le.started_at_ms, le.listened_ms, le.origin_device_id, le.started_at_ms, le.listened_ms,
le.track_duration_ms, le.metadata_json, le.track_duration_ms, le.metadata_json,
COALESCE(NULLIF(d.name, ''), le.origin_device_id) AS device_name, COALESCE(NULLIF(d.name, ''), le.origin_device_id) AS device_name,
@@ -5582,7 +5587,9 @@ async fn history_list_handler(
FROM furumusic__listen_event le FROM furumusic__listen_event le
LEFT JOIN furumusic__fed_device d LEFT JOIN furumusic__fed_device d
ON d.user_id = le.user_id AND d.device_id = le.origin_device_id ON d.user_id = le.user_id AND d.device_id = le.origin_device_id
LEFT JOIN furumusic__track t ON t.id = le.local_track_id LEFT JOIN furumusic__track_ref tr ON tr.content_id = le.content_id
LEFT JOIN furumusic__track t
ON t.id = COALESCE(le.local_track_id, tr.local_track_id)
LEFT JOIN furumusic__release r ON r.id = t.release_id LEFT JOIN furumusic__release r ON r.id = t.release_id
WHERE le.user_id = $1 AND le.qualified = true WHERE le.user_id = $1 AND le.qualified = true
ORDER BY le.started_at_ms DESC, le.listen_id DESC ORDER BY le.started_at_ms DESC, le.listen_id DESC
+5 -1
View File
@@ -1626,7 +1626,11 @@
x-text="'-' + formatTime(Math.max(0, $store.player.duration - $store.player.currentTime)) + ' / ' + formatTime($store.player.duration)"></div> x-text="'-' + formatTime(Math.max(0, $store.player.duration - $store.player.currentTime)) + ' / ' + formatTime($store.player.duration)"></div>
<span class="player-time" x-text="formatTime($store.player.duration)"></span> <span class="player-time" x-text="formatTime($store.player.duration)"></span>
</div> </div>
<div class="player-version-chip">v{{ t.app_version() }}</div> <a class="player-version-chip"
href="https://github.com/house-of-vanity/furumusic"
target="_blank"
rel="noopener noreferrer"
aria-label="Furumusic on GitHub">v{{ t.app_version() }}</a>
</div> </div>
<div class="player-right"> <div class="player-right">
+10 -1
View File
@@ -2437,7 +2437,16 @@ button.user-stat:hover {
line-height: 1; line-height: 1;
font-weight: 500; font-weight: 500;
text-align: center; text-align: center;
pointer-events: none; text-decoration: none;
pointer-events: auto;
transition: opacity 120ms ease;
}
.player-version-chip:hover,
.player-version-chip:focus-visible {
color: var(--text-subdued);
opacity: 0.9;
text-decoration: none;
} }
.mobile-account-chip { .mobile-account-chip {