server: - backup exporter, auth extractors, error shapes, CONTEXT (prior work) - spa assets served outside the rate limit via route_layer - requests_per_second went to per_second(), which takes an interval not a rate: 50 meant one request per 50s once burst was spent. now converted properly. 15/s, burst 60 spa fixes: - account delete cleared snake_case token keys that were never written - refresh interceptor could retry forever - date ranges used local day boundaries stamped +00:00 - "all" period trend plotted one page; calendar days fabricated mood 3 - chart grid invisible: hsl(var(--border)) against rgba tokens - blob url leak, orphaned media on failed save, devtools in prod bundle - pt-safe/safe-area-pb classes never existed spa features: - offline outbox: entries queue to IndexedDB, replay with backoff, only server refusals count against an entry - drafts persist, quick-log sheet, diary infinite scroll + filters - route error boundary, stale-chunk recovery, no service worker in dev a11y + perf: - mood picker is a radiogroup, activity picker keyboard-operable, text alternatives for colour/emoji, locale week start - dark glass over the bright photo: worst case 1.4:1 -> 4.9-9.6:1 - initial payload 1095->769kB raw, 306->230kB gzip; 38 unused components and 5 deps dropped; fonts 218->133kB 53 tests added (43 spa, 10 server)
97 lines
2.7 KiB
Rust
97 lines
2.7 KiB
Rust
use sqlx::SqlitePool;
|
|
|
|
use domain::entry::MoodEntryId;
|
|
use domain::errors::DomainError;
|
|
use domain::ports::UnidentifiedSong;
|
|
use domain::song::RecordingId;
|
|
use domain::user::UserId;
|
|
|
|
use super::super::shared::db_err;
|
|
|
|
pub struct SqliteRecordingBackfillRepository {
|
|
pool: SqlitePool,
|
|
}
|
|
|
|
impl SqliteRecordingBackfillRepository {
|
|
pub fn new(pool: SqlitePool) -> Self {
|
|
Self { pool }
|
|
}
|
|
}
|
|
|
|
#[derive(sqlx::FromRow)]
|
|
struct UnidentifiedSongRow {
|
|
entry_id: String,
|
|
user_id: String,
|
|
title: String,
|
|
artist: String,
|
|
}
|
|
|
|
#[async_trait::async_trait]
|
|
impl domain::ports::RecordingBackfillQueryPort for SqliteRecordingBackfillRepository {
|
|
async fn find_songs_without_a_recording(
|
|
&self,
|
|
most: usize,
|
|
) -> Result<Vec<UnidentifiedSong>, DomainError> {
|
|
let rows: Vec<UnidentifiedSongRow> = sqlx::query_as(
|
|
"SELECT s.entry_id, e.user_id, s.title, s.artist
|
|
FROM entry_song s
|
|
JOIN mood_entries e ON e.id = s.entry_id
|
|
WHERE s.recording_id IS NULL
|
|
ORDER BY e.logged_at DESC
|
|
LIMIT ?",
|
|
)
|
|
.bind(most_as_limit(most))
|
|
.fetch_all(&self.pool)
|
|
.await
|
|
.map_err(db_err)?;
|
|
|
|
Ok(rows.iter().filter_map(readable).collect())
|
|
}
|
|
|
|
async fn find_song_without_a_recording(
|
|
&self,
|
|
entry_id: &MoodEntryId,
|
|
) -> Result<Option<UnidentifiedSong>, DomainError> {
|
|
let row: Option<UnidentifiedSongRow> = sqlx::query_as(
|
|
"SELECT s.entry_id, e.user_id, s.title, s.artist
|
|
FROM entry_song s
|
|
JOIN mood_entries e ON e.id = s.entry_id
|
|
WHERE s.recording_id IS NULL AND s.entry_id = ?",
|
|
)
|
|
.bind(entry_id.value().to_string())
|
|
.fetch_optional(&self.pool)
|
|
.await
|
|
.map_err(db_err)?;
|
|
|
|
Ok(row.as_ref().and_then(readable))
|
|
}
|
|
|
|
async fn record_identity(
|
|
&self,
|
|
entry_id: &MoodEntryId,
|
|
recording_id: &RecordingId,
|
|
) -> Result<(), DomainError> {
|
|
sqlx::query("UPDATE entry_song SET recording_id = ? WHERE entry_id = ?")
|
|
.bind(recording_id.value().to_string())
|
|
.bind(entry_id.value().to_string())
|
|
.execute(&self.pool)
|
|
.await
|
|
.map_err(db_err)?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
fn most_as_limit(most: usize) -> i64 {
|
|
i64::try_from(most).unwrap_or(i64::MAX)
|
|
}
|
|
|
|
fn readable(row: &UnidentifiedSongRow) -> Option<UnidentifiedSong> {
|
|
Some(UnidentifiedSong {
|
|
entry_id: MoodEntryId::from_uuid(row.entry_id.parse().ok()?),
|
|
user_id: UserId::from_uuid(row.user_id.parse().ok()?),
|
|
title: row.title.clone(),
|
|
artist: row.artist.clone(),
|
|
})
|
|
}
|