aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-23 20:13:30 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:04:05 +0200
commit8cd72bd37724054f8942f2fefc7aa2e60eca74cf (patch)
treef2ed8da2a5a804286335156283659e9eaec5291a /server/initializers
parent5bcfd02974389e1a131496d22f4321a79bed0fbb (diff)
downloadPeerTube-8cd72bd37724054f8942f2fefc7aa2e60eca74cf.tar.gz
PeerTube-8cd72bd37724054f8942f2fefc7aa2e60eca74cf.tar.zst
PeerTube-8cd72bd37724054f8942f2fefc7aa2e60eca74cf.zip
Optimize SQL queries
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0235-delete-some-video-indexes.ts41
2 files changed, 42 insertions, 1 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 9f220aea5..e66ebb662 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -14,7 +14,7 @@ let config: IConfig = require('config')
14 14
15// --------------------------------------------------------------------------- 15// ---------------------------------------------------------------------------
16 16
17const LAST_MIGRATION_VERSION = 230 17const LAST_MIGRATION_VERSION = 235
18 18
19// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
20 20
diff --git a/server/initializers/migrations/0235-delete-some-video-indexes.ts b/server/initializers/migrations/0235-delete-some-video-indexes.ts
new file mode 100644
index 000000000..e362f240c
--- /dev/null
+++ b/server/initializers/migrations/0235-delete-some-video-indexes.ts
@@ -0,0 +1,41 @@
1import * as Sequelize from 'sequelize'
2import { createClient } from 'redis'
3import { CONFIG } from '../constants'
4import { JobQueue } from '../../lib/job-queue'
5import { initDatabaseModels } from '../database'
6
7async function up (utils: {
8 transaction: Sequelize.Transaction
9 queryInterface: Sequelize.QueryInterface
10 sequelize: Sequelize.Sequelize
11}): Promise<any> {
12 await utils.sequelize.query('DROP INDEX IF EXISTS video_id_privacy_state_wait_transcoding;')
13 await utils.sequelize.query('DROP INDEX IF EXISTS video_name;')
14
15 for (let i = 0; i < 5; i++) {
16 const query = 'DELETE FROM "videoFile" WHERE id IN ' +
17 '(SELECT id FROM (SELECT MIN(id) AS id, "videoId", "resolution", "fps" ' +
18 'FROM "videoFile" GROUP BY "videoId", "resolution", "fps" HAVING COUNT(*) > 1) t)'
19 await utils.sequelize.query(query)
20 }
21
22 for (let i = 0; i < 5; i++) {
23 const query = 'DELETE FROM "actor" WHERE id IN ' +
24 '(SELECT id FROM (SELECT MIN(id) AS id, "uuid" ' +
25 'FROM "actor" GROUP BY "uuid" HAVING COUNT(*) > 1) t)'
26 await utils.sequelize.query(query)
27 }
28
29 for (let i = 0; i < 5; i++) {
30 const query = 'DELETE FROM "account" WHERE id IN ' +
31 '(SELECT id FROM (SELECT MIN(id) AS id, "actorId" ' +
32 'FROM "account" GROUP BY "actorId" HAVING COUNT(*) > 1) t)'
33 await utils.sequelize.query(query)
34 }
35}
36
37function down (options) {
38 throw new Error('Not implemented.')
39}
40
41export { up, down }