fix: duplicate page position bug (#1431)

This commit is contained in:
Philip Okugbe
2025-07-30 18:07:06 +01:00
committed by GitHub
parent e74ecb2604
commit 39550fe906

View File

@ -261,35 +261,7 @@ export class PageService {
if (isDuplicateInSameSpace) {
// For duplicate in same space, position right after the original page
let siblingQuery = this.db
.selectFrom('pages')
.select(['position'])
.where('spaceId', '=', rootPage.spaceId)
.where('position', '>', rootPage.position);
if (rootPage.parentPageId) {
siblingQuery = siblingQuery.where(
'parentPageId',
'=',
rootPage.parentPageId,
);
} else {
siblingQuery = siblingQuery.where('parentPageId', 'is', null);
}
const nextSibling = await siblingQuery
.orderBy('position', 'asc')
.limit(1)
.executeTakeFirst();
if (nextSibling) {
nextPosition = generateJitteredKeyBetween(
rootPage.position,
nextSibling.position,
);
} else {
nextPosition = generateJitteredKeyBetween(rootPage.position, null);
}
} else {
// For copy to different space, position at the end
nextPosition = await this.nextPagePosition(spaceId);
@ -434,7 +406,10 @@ export class PageService {
attachment.id,
newAttachmentId,
);
try {
await this.storageService.copy(attachment.filePath, newPathFile);
await this.db
.insertInto('attachments')
.values({
@ -452,7 +427,14 @@ export class PageService {
})
.execute();
} catch (err) {
this.logger.log(err);
this.logger.error(
`Duplicate page: failed to copy attachment ${attachment.id}`,
err,
);
// Continue with other attachments even if one fails
}
} catch (err) {
this.logger.error(err);
}
}
}