Skip to content

Commit 460d68c

Browse files
authored
chore(trash-expiration): added new partial index and drop old index (#998)
1 parent cc21635 commit 460d68c

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const indexName = 'idx_files_updated_at_user_id';
4+
5+
module.exports = {
6+
async up(queryInterface, Sequelize) {
7+
await queryInterface.sequelize.query(`
8+
CREATE INDEX CONCURRENTLY IF NOT EXISTS ${indexName}
9+
ON files (updated_at, user_id, uuid)
10+
WHERE status = 'TRASHED'
11+
`);
12+
},
13+
14+
async down(queryInterface, Sequelize) {
15+
await queryInterface.sequelize.query(`
16+
DROP INDEX CONCURRENTLY IF EXISTS ${indexName}
17+
`);
18+
},
19+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const indexName = 'idx_files_status_trash';
4+
5+
module.exports = {
6+
async up(queryInterface, Sequelize) {
7+
await queryInterface.sequelize.query(
8+
`DROP INDEX CONCURRENTLY IF EXISTS ${indexName}`,
9+
);
10+
},
11+
12+
async down(queryInterface, Sequelize) {
13+
await queryInterface.sequelize.query(
14+
`CREATE INDEX CONCURRENTLY IF NOT EXISTS ${indexName} ON files (user_id, updated_at, uuid) WHERE status = 'TRASHED'`,
15+
);
16+
},
17+
};

src/modules/jobs/tasks/delete-expired-trash-items.task.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,6 @@ export class DeleteExpiredTrashItemsTask implements BeforeApplicationShutdown {
225225
}
226226

227227
totalDeleted += deletedUuids.length;
228-
229-
// TODO: Remove the delay after ensuring the deletion queue is not overwhelmed
230-
await new Promise((resolve) =>
231-
setTimeout(resolve, 500 + Math.random() * 1500),
232-
);
233228
} while (deletedUuids.length === this.batchSize);
234229

235230
onFinish(totalDeleted);

0 commit comments

Comments
 (0)