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