diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/model-cache.ts | 6 | ||||
-rw-r--r-- | server/models/video/video.ts | 36 |
2 files changed, 32 insertions, 10 deletions
diff --git a/server/models/model-cache.ts b/server/models/model-cache.ts index 8afe3834f..a87f99aa2 100644 --- a/server/models/model-cache.ts +++ b/server/models/model-cache.ts | |||
@@ -6,7 +6,8 @@ type ModelCacheType = | |||
6 | 'local-account-name' | 6 | 'local-account-name' |
7 | | 'local-actor-name' | 7 | | 'local-actor-name' |
8 | | 'local-actor-url' | 8 | | 'local-actor-url' |
9 | | 'video-immutable' | 9 | | 'load-video-immutable-id' |
10 | | 'load-video-immutable-url' | ||
10 | 11 | ||
11 | type DeleteKey = | 12 | type DeleteKey = |
12 | 'video' | 13 | 'video' |
@@ -19,7 +20,8 @@ class ModelCache { | |||
19 | 'local-account-name': new Map(), | 20 | 'local-account-name': new Map(), |
20 | 'local-actor-name': new Map(), | 21 | 'local-actor-name': new Map(), |
21 | 'local-actor-url': new Map(), | 22 | 'local-actor-url': new Map(), |
22 | 'video-immutable': new Map() | 23 | 'load-video-immutable-id': new Map(), |
24 | 'load-video-immutable-url': new Map() | ||
23 | } | 25 | } |
24 | 26 | ||
25 | private readonly deleteIds: { | 27 | private readonly deleteIds: { |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 9e02d163f..5964526a9 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -145,6 +145,7 @@ export enum ScopeNames { | |||
145 | WITH_USER_HISTORY = 'WITH_USER_HISTORY', | 145 | WITH_USER_HISTORY = 'WITH_USER_HISTORY', |
146 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', | 146 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', |
147 | WITH_USER_ID = 'WITH_USER_ID', | 147 | WITH_USER_ID = 'WITH_USER_ID', |
148 | WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES', | ||
148 | WITH_THUMBNAILS = 'WITH_THUMBNAILS' | 149 | WITH_THUMBNAILS = 'WITH_THUMBNAILS' |
149 | } | 150 | } |
150 | 151 | ||
@@ -188,6 +189,9 @@ export type AvailableForListIDsOptions = { | |||
188 | } | 189 | } |
189 | 190 | ||
190 | @Scopes(() => ({ | 191 | @Scopes(() => ({ |
192 | [ScopeNames.WITH_IMMUTABLE_ATTRIBUTES]: { | ||
193 | attributes: [ 'id', 'url', 'uuid', 'remote' ] | ||
194 | }, | ||
191 | [ScopeNames.FOR_API]: (options: ForAPIOptions) => { | 195 | [ScopeNames.FOR_API]: (options: ForAPIOptions) => { |
192 | const query: FindOptions = { | 196 | const query: FindOptions = { |
193 | include: [ | 197 | include: [ |
@@ -1476,20 +1480,16 @@ export class VideoModel extends Model<VideoModel> { | |||
1476 | 1480 | ||
1477 | static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> { | 1481 | static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> { |
1478 | const fun = () => { | 1482 | const fun = () => { |
1479 | const where = buildWhereIdOrUUID(id) | 1483 | const query = { |
1480 | const options = { | 1484 | where: buildWhereIdOrUUID(id), |
1481 | attributes: [ | ||
1482 | 'id', 'url', 'uuid' | ||
1483 | ], | ||
1484 | where, | ||
1485 | transaction: t | 1485 | transaction: t |
1486 | } | 1486 | } |
1487 | 1487 | ||
1488 | return VideoModel.unscoped().findOne(options) | 1488 | return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query) |
1489 | } | 1489 | } |
1490 | 1490 | ||
1491 | return ModelCache.Instance.doCache({ | 1491 | return ModelCache.Instance.doCache({ |
1492 | cacheType: 'video-immutable', | 1492 | cacheType: 'load-video-immutable-id', |
1493 | key: '' + id, | 1493 | key: '' + id, |
1494 | deleteKey: 'video', | 1494 | deleteKey: 'video', |
1495 | fun | 1495 | fun |
@@ -1559,6 +1559,26 @@ export class VideoModel extends Model<VideoModel> { | |||
1559 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) | 1559 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) |
1560 | } | 1560 | } |
1561 | 1561 | ||
1562 | static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Bluebird<MVideoImmutable> { | ||
1563 | const fun = () => { | ||
1564 | const query: FindOptions = { | ||
1565 | where: { | ||
1566 | url | ||
1567 | }, | ||
1568 | transaction | ||
1569 | } | ||
1570 | |||
1571 | return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query) | ||
1572 | } | ||
1573 | |||
1574 | return ModelCache.Instance.doCache({ | ||
1575 | cacheType: 'load-video-immutable-url', | ||
1576 | key: url, | ||
1577 | deleteKey: 'video', | ||
1578 | fun | ||
1579 | }) | ||
1580 | } | ||
1581 | |||
1562 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> { | 1582 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> { |
1563 | const query: FindOptions = { | 1583 | const query: FindOptions = { |
1564 | where: { | 1584 | where: { |