chore(frontend): fetch latest PingEvent timestamp in repository for sync operations

- Added `selectLatestPingEventTimestamp` query to `AppDatabase`.
- Updated `PingEventRepositoryImpl` to use the timestamp for `since` parameter instead of the event ID.
This commit is contained in:
2026-02-01 17:56:12 +01:00
parent 05e85ff98e
commit 5ff720f875
2 changed files with 17 additions and 4 deletions
@@ -36,6 +36,12 @@ FROM PingEvent
ORDER BY id DESC
LIMIT 1;
selectLatestPingEventTimestamp:
SELECT last_modified
FROM PingEvent
ORDER BY last_modified DESC
LIMIT 1;
upsertPingEvents:
-- SQLite dialect configured for this project is 3.18 (no UPSERT support).
-- Use INSERT OR REPLACE as pragmatic upsert.
@@ -14,11 +14,18 @@ class PingEventRepositoryImpl(
private val db: AppDatabase
) : SyncableRepository<PingEvent> {
// Der `since`-Parameter für unsere Synchronisierung ist die ID des letzten Ereignisses, kein Zeitstempel.
// Der `since`-Parameter für unsere Synchronisierung ist der Zeitstempel des letzten Ereignisses.
// Das Backend erwartet einen Long (Timestamp), keinen String (UUID).
override suspend fun getLatestSince(): String? {
println("PingEventRepositoryImpl: getLatestSince called - using corrected async implementation")
// FIX: Verwenden Sie .awaitAsOneOrNull() für asynchrone Treiber anstelle des blockierenden .executeAsOneOrNull().
return db.appDatabaseQueries.selectLatestPingEventId().awaitAsOneOrNull()
println("PingEventRepositoryImpl: getLatestSince called - fetching latest timestamp")
// Wir holen den letzten Timestamp aus der DB.
val lastModified = db.appDatabaseQueries.selectLatestPingEventTimestamp().awaitAsOneOrNull()
// Wir geben ihn als String zurück, da das Interface String? erwartet.
// Der SyncManager wird ihn als Parameter "since" an den Request hängen.
// Das Backend erwartet "since" als Long, aber HTTP Parameter sind Strings.
// Spring Boot konvertiert "123456789" automatisch in Long 123456789.
return lastModified?.toString()
}
override suspend fun upsert(items: List<PingEvent>) {