Persist session sort keys in overview cache
This commit is contained in:
1 parent
a4a6632707
commit
56e15fd9b4
3 files changed
+15
-4
No files matched your search
@@ -16,6 +16,7 @@ data class OverviewSessionSnapshot(
|
||||
val title: String,
|
||||
val lastMessage: String,
|
||||
val updatedAt: String,
|
||||
val sortKey: Long? = null,
|
||||
val isPinned: Boolean = false,
|
||||
val unreadCount: Int = 0,
|
||||
val streamStatus: String? = null,
|
||||
@@ -38,11 +39,12 @@ fun ServerStatus.toSnapshot(): OverviewStatusSnapshot = OverviewStatusSnapshot(
|
||||
updatedAt = updatedAt,
|
||||
)
|
||||
|
||||
fun SessionSummary.toSnapshot(): OverviewSessionSnapshot = OverviewSessionSnapshot(
|
||||
fun SessionSummary.toSnapshot(sortKey: Long? = null): OverviewSessionSnapshot = OverviewSessionSnapshot(
|
||||
id = id,
|
||||
title = title,
|
||||
lastMessage = lastMessage,
|
||||
updatedAt = updatedAt,
|
||||
sortKey = sortKey,
|
||||
isPinned = isPinned,
|
||||
unreadCount = unreadCount,
|
||||
streamStatus = streamStatus,
|
||||
|
||||
+10
-2
@@ -82,7 +82,7 @@ class RemoteOpenClawRepository(
|
||||
override fun hydrateOverview(snapshot: OverviewSnapshot) {
|
||||
availableAgents = snapshot.availableAgents
|
||||
sessions = snapshot.sessions.map { it.toDomain() }
|
||||
rebuildSessionSortKeys(sessions)
|
||||
rebuildSessionSortKeys(snapshot.sessions)
|
||||
status = snapshot.status.toDomain()
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ class RemoteOpenClawRepository(
|
||||
|
||||
fun exportOverviewSnapshot(): OverviewSnapshot = OverviewSnapshot(
|
||||
availableAgents = availableAgents,
|
||||
sessions = sessions.map { it.toSnapshot() },
|
||||
sessions = sessions.map { session -> session.toSnapshot(sortKey = sessionSortKeyStore[session.id]) },
|
||||
status = status.toSnapshot(),
|
||||
savedAt = status.updatedAt,
|
||||
)
|
||||
@@ -652,6 +652,14 @@ class RemoteOpenClawRepository(
|
||||
}
|
||||
}
|
||||
|
||||
private fun rebuildSessionSortKeys(items: List<OverviewSessionSnapshot>) {
|
||||
val total = items.size.toLong()
|
||||
items.forEachIndexed { index, session ->
|
||||
val fallback = (total - index).coerceAtLeast(1L)
|
||||
sessionSortKeyStore[session.id] = session.sortKey ?: parseDisplaySortKey(session.updatedAt) ?: fallback
|
||||
}
|
||||
}
|
||||
|
||||
private fun rebuildSessionSortKeys(items: List<SessionSummary>) {
|
||||
val total = items.size.toLong()
|
||||
items.forEachIndexed { index, session ->
|
||||
|
||||
Reference in new issue
Block a user