Skip to content

Commit

Permalink
Fix document updateAt mapping (#254)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
blurfx authored Jul 26, 2024
1 parent fd62043 commit e184d24
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions backend/src/workspace-documents/workspace-documents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
});
Expand Down

0 comments on commit e184d24

Please sign in to comment.