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:
+6
@@ -36,6 +36,12 @@ FROM PingEvent
|
|||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
|
selectLatestPingEventTimestamp:
|
||||||
|
SELECT last_modified
|
||||||
|
FROM PingEvent
|
||||||
|
ORDER BY last_modified DESC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
upsertPingEvents:
|
upsertPingEvents:
|
||||||
-- SQLite dialect configured for this project is 3.18 (no UPSERT support).
|
-- SQLite dialect configured for this project is 3.18 (no UPSERT support).
|
||||||
-- Use INSERT OR REPLACE as pragmatic upsert.
|
-- Use INSERT OR REPLACE as pragmatic upsert.
|
||||||
|
|||||||
+11
-4
@@ -14,11 +14,18 @@ class PingEventRepositoryImpl(
|
|||||||
private val db: AppDatabase
|
private val db: AppDatabase
|
||||||
) : SyncableRepository<PingEvent> {
|
) : 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? {
|
override suspend fun getLatestSince(): String? {
|
||||||
println("PingEventRepositoryImpl: getLatestSince called - using corrected async implementation")
|
println("PingEventRepositoryImpl: getLatestSince called - fetching latest timestamp")
|
||||||
// FIX: Verwenden Sie .awaitAsOneOrNull() für asynchrone Treiber anstelle des blockierenden .executeAsOneOrNull().
|
// Wir holen den letzten Timestamp aus der DB.
|
||||||
return db.appDatabaseQueries.selectLatestPingEventId().awaitAsOneOrNull()
|
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>) {
|
override suspend fun upsert(items: List<PingEvent>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user