Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Optimize views sort sql query

Chocobozzz534556052ed4
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 6aaef3aa20..1623e6f42c 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
// ---------------------------------------------------------------------------
-const LAST_MIGRATION_VERSION = 605
+const LAST_MIGRATION_VERSION = 610
// ---------------------------------------------------------------------------
diff --git a/server/initializers/migrations/0610-views-index.ts b/server/initializers/migrations/0610-views-index.ts
new file mode 100644
index 0000000000..02ee21172c
--- /dev/null
+++ b/server/initializers/migrations/0610-views-index.ts
@@ -0,0 +1,20 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+ transaction: Sequelize.Transaction
+ queryInterface: Sequelize.QueryInterface
+ sequelize: Sequelize.Sequelize
+ db: any
+}): Promise<void> {
+
+ await utils.sequelize.query('DROP INDEX IF EXISTS video_views;')
+}
+
+function down (options) {
+ throw new Error('Not implemented.')
+}
+
+export {
+ up,
+ down
+}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index b4c7da655b..b3543ddf24 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -426,7 +426,12 @@ export type AvailableForListIDsOptions = {
]
},
{ fields: [ 'duration' ] },
- { fields: [ 'views' ] },
+ {
+ fields: [
+ { name: 'views', order: 'DESC' },
+ { name: 'id', order: 'ASC' }
+ ]
+ },
{ fields: [ 'channelId' ] },
{
fields: [ 'originallyPublishedAt' ],