From e184d2482de04f0e8e0d3f7a51c00d70f4addbc7 Mon Sep 17 00:00:00 2001 From: changhui lee Date: Fri, 26 Jul 2024 09:39:59 +0900 Subject: [PATCH] Fix document updateAt mapping (#254) There was an issue with the updatedAt of a document showing another document updatedAt. Specifically, the updatedAt in the document list was being reversed and reflecting a different document's value. This issue occured during the bulk retrieval of document lists using yorkie-team/yorkie#931. In this process, there was no guarantee that the order of the keys passed to the DB query matches the order of the documents in the query result. --- .../workspace-documents.service.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/src/workspace-documents/workspace-documents.service.ts b/backend/src/workspace-documents/workspace-documents.service.ts index d8b1ddf8..eed5f9a2 100644 --- a/backend/src/workspace-documents/workspace-documents.service.ts +++ b/backend/src/workspace-documents/workspace-documents.service.ts @@ -82,13 +82,16 @@ export class WorkspaceDocumentsService { const yorkieDocumentList = await this.findManyFromYorkie( slicedDocumentList.map((doc) => doc.yorkieDocumentId) ); - const mergedDocumentList = slicedDocumentList.map((doc, idx) => { - const yorkieDocument = yorkieDocumentList.documents?.[idx]; + const yorkieDocumentMap = new Map( + yorkieDocumentList.documents?.map((doc) => [doc.key, doc]) + ); + const mergedDocumentList = slicedDocumentList.map((doc) => { + const yorkieDocumentUpdatedAt = yorkieDocumentMap.get(doc.yorkieDocumentId)?.updatedAt; return { ...doc, - updatedAt: yorkieDocument?.updatedAt - ? moment(yorkieDocument.updatedAt).toDate() + updatedAt: yorkieDocumentUpdatedAt + ? moment(yorkieDocumentUpdatedAt).toDate() : doc.updatedAt, }; });