Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/domain/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/infra/repository/dbBookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -716,8 +716,9 @@ export class BookmarkRepo {
}
},
orderBy: {
created_at: 'desc'
}
created_at: 'asc'
},
take: limit
})

return res as bookmarkActionChangePO[]
Expand Down
6 changes: 5 additions & 1 deletion src/infra/repository/dbSyncBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading