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:
parent
cd877f64cd
commit
024967ce60
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user