From 890682c41e765acee66eb688a62c333392ac7f2b Mon Sep 17 00:00:00 2001 From: James McNamara Date: Mon, 2 Sep 2024 06:47:36 -0700 Subject: [PATCH] CODY-3538: Fixed chat-id bug in migration (#2176) Tie in for https://github.com/sourcegraph/cody/pull/5407. Properly constructs chat transcripts and during import. ## Test plan Updated unit tests --------- Co-authored-by: Piotr Kukielka --- .../cody/config/migration/ChatHistoryMigration.kt | 6 +++--- .../cody/config/migration/SettingsMigration.kt | 2 +- .../com/sourcegraph/cody/config/SettingsMigrationTest.kt | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/sourcegraph/cody/config/migration/ChatHistoryMigration.kt b/src/main/kotlin/com/sourcegraph/cody/config/migration/ChatHistoryMigration.kt index 9c84ca30e0..1f68dbaecc 100644 --- a/src/main/kotlin/com/sourcegraph/cody/config/migration/ChatHistoryMigration.kt +++ b/src/main/kotlin/com/sourcegraph/cody/config/migration/ChatHistoryMigration.kt @@ -33,16 +33,16 @@ object ChatHistoryMigration { return chats .map { (account, chats) -> val serializedChats = chats.mapNotNull(::toSerializedChatTranscript) - val byId = serializedChats.associateBy { it.id } + val byTimestamp = serializedChats.associateBy { it.lastInteractionTimestamp } - "${account.server.url}-${account.name}" to byId + "${account.server.url}-${account.name}" to byTimestamp } .toMap() } private fun toSerializedChatTranscript(chat: ChatState): SerializedChatTranscript? { return SerializedChatTranscript( - id = chat.internalId ?: return null, + id = chat.updatedAt ?: return null, lastInteractionTimestamp = chat.updatedAt ?: return null, interactions = toSerializedInteractions(chat.messages, chat.llm?.model), ) diff --git a/src/main/kotlin/com/sourcegraph/cody/config/migration/SettingsMigration.kt b/src/main/kotlin/com/sourcegraph/cody/config/migration/SettingsMigration.kt index 0659b7a401..6a4242db1f 100644 --- a/src/main/kotlin/com/sourcegraph/cody/config/migration/SettingsMigration.kt +++ b/src/main/kotlin/com/sourcegraph/cody/config/migration/SettingsMigration.kt @@ -64,7 +64,7 @@ class SettingsMigration : Activity { DeprecatedChatLlmMigration.migrate(project) ChatTagsLlmMigration.migrate(project) - RunOnceUtil.runOnceForProject(project, "CodyMigrateChatHistory") { + RunOnceUtil.runOnceForProject(project, "CodyMigrateChatHistory-v2") { ChatHistoryMigration.migrate(project) } } diff --git a/src/test/kotlin/com/sourcegraph/cody/config/SettingsMigrationTest.kt b/src/test/kotlin/com/sourcegraph/cody/config/SettingsMigrationTest.kt index bbbe825b61..7f50f81deb 100644 --- a/src/test/kotlin/com/sourcegraph/cody/config/SettingsMigrationTest.kt +++ b/src/test/kotlin/com/sourcegraph/cody/config/SettingsMigrationTest.kt @@ -436,9 +436,9 @@ class SettingsMigrationTest : BasePlatformTestCase() { mapOf( "https://sourcegraph.com-account1" to mapOf( - chat1.internalId to + chat1.updatedAt!! to SerializedChatTranscript( - id = chat1.internalId!!, + id = chat1.updatedAt!!, lastInteractionTimestamp = chat1.updatedAt!!, interactions = listOf( @@ -457,9 +457,9 @@ class SettingsMigrationTest : BasePlatformTestCase() { .Assistant))))), "https://sourcegraph.com-account2" to mapOf( - chat2.internalId to + chat2.updatedAt to SerializedChatTranscript( - id = chat2.internalId!!, + id = chat2.updatedAt!!, lastInteractionTimestamp = chat2.updatedAt!!, interactions = listOf(