Skip to content

Commit

Permalink
CODY-3538: Fixed chat-id bug in migration (#2176)
Browse files Browse the repository at this point in the history
Tie in for sourcegraph/cody#5407. Properly
constructs chat transcripts and during import.

## Test plan
Updated unit tests

---------

Co-authored-by: Piotr Kukielka <[email protected]>
  • Loading branch information
jamesmcnamara and pkukielka authored Sep 2, 2024
1 parent e8cbbc8 commit 890682c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 890682c

Please sign in to comment.