aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-29 09:33:28 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-29 10:04:39 +0100
commit319d072e8eb7266cd8d33e0bb2fb5ebe76c487d1 (patch)
tree33735d94f0f928e80486f82bcc21fdf233b5b445 /server
parent67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677 (diff)
downloadPeerTube-319d072e8eb7266cd8d33e0bb2fb5ebe76c487d1.tar.gz
PeerTube-319d072e8eb7266cd8d33e0bb2fb5ebe76c487d1.tar.zst
PeerTube-319d072e8eb7266cd8d33e0bb2fb5ebe76c487d1.zip
Server: Add postgresql indexes
Diffstat (limited to 'server')
-rw-r--r--server/models/author.js8
-rw-r--r--server/models/oauth-client.js22
-rw-r--r--server/models/oauth-token.js24
-rw-r--r--server/models/pod.js8
-rw-r--r--server/models/requestToPod.js12
-rw-r--r--server/models/tag.js7
-rw-r--r--server/models/user.js5
-rw-r--r--server/models/video.js20
-rw-r--r--server/models/videoTag.js11
9 files changed, 104 insertions, 13 deletions
diff --git a/server/models/author.js b/server/models/author.js
index e0ac868ea..8f5b598c8 100644
--- a/server/models/author.js
+++ b/server/models/author.js
@@ -17,6 +17,14 @@ module.exports = function (sequelize, DataTypes) {
17 } 17 }
18 }, 18 },
19 { 19 {
20 indexes: [
21 {
22 fields: [ 'name' ]
23 },
24 {
25 fields: [ 'podId' ]
26 }
27 ],
20 classMethods: { 28 classMethods: {
21 associate 29 associate
22 } 30 }
diff --git a/server/models/oauth-client.js b/server/models/oauth-client.js
index b56838d4c..758c4cf2f 100644
--- a/server/models/oauth-client.js
+++ b/server/models/oauth-client.js
@@ -19,9 +19,17 @@ module.exports = function (sequelize, DataTypes) {
19 } 19 }
20 }, 20 },
21 { 21 {
22 indexes: [
23 {
24 fields: [ 'clientId' ],
25 unique: true
26 },
27 {
28 fields: [ 'clientId', 'clientSecret' ],
29 unique: true
30 }
31 ],
22 classMethods: { 32 classMethods: {
23 associate,
24
25 getByIdAndSecret, 33 getByIdAndSecret,
26 list, 34 list,
27 loadFirstClient 35 loadFirstClient
@@ -34,16 +42,6 @@ module.exports = function (sequelize, DataTypes) {
34 42
35// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------
36 44
37function associate (models) {
38 this.hasMany(models.OAuthToken, {
39 foreignKey: {
40 name: 'oAuthClientId',
41 allowNull: false
42 },
43 onDelete: 'cascade'
44 })
45}
46
47function list (callback) { 45function list (callback) {
48 return this.findAll().asCallback(callback) 46 return this.findAll().asCallback(callback)
49} 47}
diff --git a/server/models/oauth-token.js b/server/models/oauth-token.js
index f8de4e916..68e7c9ff7 100644
--- a/server/models/oauth-token.js
+++ b/server/models/oauth-token.js
@@ -25,6 +25,22 @@ module.exports = function (sequelize, DataTypes) {
25 } 25 }
26 }, 26 },
27 { 27 {
28 indexes: [
29 {
30 fields: [ 'refreshToken' ],
31 unique: true
32 },
33 {
34 fields: [ 'accessToken' ],
35 unique: true
36 },
37 {
38 fields: [ 'userId' ]
39 },
40 {
41 fields: [ 'oAuthClientId' ]
42 }
43 ],
28 classMethods: { 44 classMethods: {
29 associate, 45 associate,
30 46
@@ -49,6 +65,14 @@ function associate (models) {
49 }, 65 },
50 onDelete: 'cascade' 66 onDelete: 'cascade'
51 }) 67 })
68
69 this.belongsTo(models.OAuthClient, {
70 foreignKey: {
71 name: 'oAuthClientId',
72 allowNull: false
73 },
74 onDelete: 'cascade'
75 })
52} 76}
53 77
54function getByRefreshTokenAndPopulateClient (refreshToken) { 78function getByRefreshTokenAndPopulateClient (refreshToken) {
diff --git a/server/models/pod.js b/server/models/pod.js
index 84f78f200..83ecd732e 100644
--- a/server/models/pod.js
+++ b/server/models/pod.js
@@ -35,6 +35,14 @@ module.exports = function (sequelize, DataTypes) {
35 } 35 }
36 }, 36 },
37 { 37 {
38 indexes: [
39 {
40 fields: [ 'host' ]
41 },
42 {
43 fields: [ 'score' ]
44 }
45 ],
38 classMethods: { 46 classMethods: {
39 associate, 47 associate,
40 48
diff --git a/server/models/requestToPod.js b/server/models/requestToPod.js
index 378c2bdcf..f42a53458 100644
--- a/server/models/requestToPod.js
+++ b/server/models/requestToPod.js
@@ -4,6 +4,18 @@
4 4
5module.exports = function (sequelize, DataTypes) { 5module.exports = function (sequelize, DataTypes) {
6 const RequestToPod = sequelize.define('RequestToPod', {}, { 6 const RequestToPod = sequelize.define('RequestToPod', {}, {
7 indexes: [
8 {
9 fields: [ 'requestId' ]
10 },
11 {
12 fields: [ 'podId' ]
13 },
14 {
15 fields: [ 'requestId', 'podId' ],
16 unique: true
17 }
18 ],
7 classMethods: { 19 classMethods: {
8 removePodOf 20 removePodOf
9 } 21 }
diff --git a/server/models/tag.js b/server/models/tag.js
index d6c2d3bb1..27eecdc84 100644
--- a/server/models/tag.js
+++ b/server/models/tag.js
@@ -11,6 +11,13 @@ module.exports = function (sequelize, DataTypes) {
11 } 11 }
12 }, 12 },
13 { 13 {
14 timestamps: false,
15 indexes: [
16 {
17 fields: [ 'name' ],
18 unique: true
19 }
20 ],
14 classMethods: { 21 classMethods: {
15 associate 22 associate
16 } 23 }
diff --git a/server/models/user.js b/server/models/user.js
index 944986a44..631cd96c9 100644
--- a/server/models/user.js
+++ b/server/models/user.js
@@ -38,6 +38,11 @@ module.exports = function (sequelize, DataTypes) {
38 } 38 }
39 }, 39 },
40 { 40 {
41 indexes: [
42 {
43 fields: [ 'username' ]
44 }
45 ],
41 classMethods: { 46 classMethods: {
42 associate, 47 associate,
43 48
diff --git a/server/models/video.js b/server/models/video.js
index 3ebc48ad4..d1595ce51 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -82,6 +82,26 @@ module.exports = function (sequelize, DataTypes) {
82 } 82 }
83 }, 83 },
84 { 84 {
85 indexes: [
86 {
87 fields: [ 'authorId' ]
88 },
89 {
90 fields: [ 'remoteId' ]
91 },
92 {
93 fields: [ 'name' ]
94 },
95 {
96 fields: [ 'createdAt' ]
97 },
98 {
99 fields: [ 'duration' ]
100 },
101 {
102 fields: [ 'infoHash' ]
103 }
104 ],
85 classMethods: { 105 classMethods: {
86 associate, 106 associate,
87 107
diff --git a/server/models/videoTag.js b/server/models/videoTag.js
index 0f2b20838..cd9277a6e 100644
--- a/server/models/videoTag.js
+++ b/server/models/videoTag.js
@@ -3,7 +3,16 @@
3// --------------------------------------------------------------------------- 3// ---------------------------------------------------------------------------
4 4
5module.exports = function (sequelize, DataTypes) { 5module.exports = function (sequelize, DataTypes) {
6 const VideoTag = sequelize.define('VideoTag', {}, {}) 6 const VideoTag = sequelize.define('VideoTag', {}, {
7 indexes: [
8 {
9 fields: [ 'videoId' ]
10 },
11 {
12 fields: [ 'tagId' ]
13 }
14 ]
15 })
7 16
8 return VideoTag 17 return VideoTag
9} 18}