1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Server: Fixed calculating total item size after an item has been deleted

This commit is contained in:
Laurent Cozic 2021-09-18 14:46:10 +01:00
parent cd877f64cd
commit 024967ce60
2 changed files with 33 additions and 1 deletions

View File

@ -196,6 +196,34 @@ describe('ItemModel', function() {
expect((await models().user().load(user3.id)).total_item_size).toBe(totalSize3);
});
test('should update total size when an item is deleted', async function() {
const { user: user1 } = await createUserAndSession(1);
await createItemTree3(user1.id, '', '', [
{
id: '000000000000000000000000000000F1',
children: [
{
id: '00000000000000000000000000000001',
},
],
},
]);
const folder1 = await models().item().loadByJopId(user1.id, '000000000000000000000000000000F1');
const note1 = await models().item().loadByJopId(user1.id, '00000000000000000000000000000001');
await models().item().updateTotalSizes();
expect((await models().user().load(user1.id)).total_item_size).toBe(folder1.content_size + note1.content_size);
await models().item().delete(note1.id);
await models().item().updateTotalSizes();
expect((await models().user().load(user1.id)).total_item_size).toBe(folder1.content_size);
});
test('should include shared items in total size calculation', async function() {
const { user: user1, session: session1 } = await createUserAndSession(1);
const { user: user2, session: session2 } = await createUserAndSession(2);

View File

@ -623,7 +623,11 @@ export default class ItemModel extends BaseModel<Item> {
} else {
const itemIds: Uuid[] = unique(changes.map(c => c.item_id));
const userItems: UserItem[] = await this.db('user_items').select('user_id').whereIn('item_id', itemIds);
const userIds: Uuid[] = unique(userItems.map(u => u.user_id));
const userIds: Uuid[] = unique(
userItems
.map(u => u.user_id)
.concat(changes.map(c => c.user_id))
);
const totalSizes: TotalSizeRow[] = [];
for (const userId of userIds) {