1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00

Server: Save and query less data when creating and updating items (#13739)

This commit is contained in:
Henry Heino
2025-11-21 11:25:47 -08:00
committed by GitHub
parent d8920840f2
commit 6b2d9ba5ec
2 changed files with 4 additions and 10 deletions

View File

@@ -30,9 +30,6 @@ export interface ChangePagination {
}
export interface ChangePreviousItem {
name: string;
jop_parent_id: string;
jop_resource_ids: string[];
jop_share_id: string;
}

View File

@@ -993,6 +993,7 @@ export default class ItemModel extends BaseModel<Item> {
const isNew = await this.isNew(item, options);
let previousItem: ChangePreviousItem = null;
let previousName: string|null = null;
if (item.content && !item.content_storage_id) {
item.content_storage_id = (await this.storageDriver()).storageId;
@@ -1002,13 +1003,9 @@ export default class ItemModel extends BaseModel<Item> {
if (!item.mime_type) item.mime_type = mimeUtils.fromFilename(item.name) || '';
if (!item.owner_id) item.owner_id = userId;
} else {
const beforeSaveItem = (await this.load(item.id, { fields: ['name', 'jop_type', 'jop_parent_id', 'jop_share_id'] }));
const resourceIds = beforeSaveItem.jop_type === ModelType.Note ? await this.models().itemResource().byItemId(item.id) : [];
const beforeSaveItem = await this.load(item.id, { fields: ['name', 'jop_share_id'] });
previousName = beforeSaveItem.name;
previousItem = {
jop_parent_id: beforeSaveItem.jop_parent_id,
name: beforeSaveItem.name,
jop_resource_ids: resourceIds,
jop_share_id: beforeSaveItem.jop_share_id,
};
}
@@ -1029,7 +1026,7 @@ export default class ItemModel extends BaseModel<Item> {
// We only record updates. This because Create and Update events are
// per user, whenever a user_item is created or deleted.
const changeItemName = item.name || previousItem.name;
const changeItemName = item.name || previousName;
if (!isNew && this.shouldRecordChange(changeItemName)) {
await this.models().change().save({