diff options
author | Chocobozzz <me@florianbigard.com> | 2020-02-04 15:45:41 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-02-04 15:58:59 +0100 |
commit | 943e5193905908dd1f2800d8810c635d86e3b28f (patch) | |
tree | 961973733e6e4afb58ac222d2847a3fc4b6d6d60 /server/models/video/video.ts | |
parent | 7eba5e1fa81c8e54cb8fe298a96e8070afa50921 (diff) | |
download | PeerTube-943e5193905908dd1f2800d8810c635d86e3b28f.tar.gz PeerTube-943e5193905908dd1f2800d8810c635d86e3b28f.tar.zst PeerTube-943e5193905908dd1f2800d8810c635d86e3b28f.zip |
Don't refresh videos when processing views
It allows us to use a cache
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 36 |
1 files changed, 28 insertions, 8 deletions
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: { |