diff --git a/src/domain/bookmark.ts b/src/domain/bookmark.ts index 767d4b9..f7366ec 100644 --- a/src/domain/bookmark.ts +++ b/src/domain/bookmark.ts @@ -828,13 +828,16 @@ export class BookmarkService { public async getPartialBookmarkChangesLog(ctx: ContextManager, userId: number, time: number) { const res = (await this.bookmarkRepo.getPartialBookmarkChanges(userId, time)) || [] - const logs = res.map(item => ({ - target_url: item.target_url, - bookmark_id: ctx.hashIds.encodeId(item.bookmark_id), - action: item.action - })) - - const previous_sync = res.length > 0 ? res[0].created_at.getTime() : null + const previous_sync = res.length > 0 ? res[res.length - 1].created_at.getTime() : null + + const logs = res + .slice() + .reverse() + .map(item => ({ + target_url: item.target_url, + bookmark_id: ctx.hashIds.encodeId(item.bookmark_id), + action: item.action + })) return { logs, diff --git a/src/infra/repository/dbBookmark.ts b/src/infra/repository/dbBookmark.ts index 1fe64ad..ac75a96 100644 --- a/src/infra/repository/dbBookmark.ts +++ b/src/infra/repository/dbBookmark.ts @@ -707,7 +707,7 @@ export class BookmarkRepo { } } - public async getPartialBookmarkChanges(userId: number, time: number) { + public async getPartialBookmarkChanges(userId: number, time: number, limit = 5000) { const res = await this.prisma().slax_user_bookmark_change.findMany({ where: { user_id: userId, @@ -716,8 +716,9 @@ export class BookmarkRepo { } }, orderBy: { - created_at: 'desc' - } + created_at: 'asc' + }, + take: limit }) return res as bookmarkActionChangePO[] diff --git a/src/infra/repository/dbSyncBatch.ts b/src/infra/repository/dbSyncBatch.ts index 8a1a6ef..cd61224 100644 --- a/src/infra/repository/dbSyncBatch.ts +++ b/src/infra/repository/dbSyncBatch.ts @@ -100,9 +100,13 @@ export class DBSyncBatchOperation { where: { uuid: operation.bookmarkUuid } }) + if (existingByUuid && existingByUuid.user_id !== operation.userId) { + throw ShareActionNotAllowedError() + } + if (existingByUuid) { await tx.sr_user_bookmark.update({ - where: { uuid: operation.bookmarkUuid }, + where: { uuid: operation.bookmarkUuid, user_id: operation.userId }, data: { bookmark_id: bookmark.id, deleted_at: null,