aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-19 14:23:17 +0100
committerChocobozzz <me@florianbigard.com>2019-03-19 14:30:43 +0100
commitd74d29ad9e35929491cf37223398d2535ab23de0 (patch)
tree2812c9acbc05be0603eb671f8e6bd81086cf84d5 /server/lib
parent9f79ade627f0044606a9fbbe16ca0154661d12b9 (diff)
downloadPeerTube-d74d29ad9e35929491cf37223398d2535ab23de0.tar.gz
PeerTube-d74d29ad9e35929491cf37223398d2535ab23de0.tar.zst
PeerTube-d74d29ad9e35929491cf37223398d2535ab23de0.zip
Limit user tokens cache
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/files-cache/abstract-video-static-file-cache.ts (renamed from server/lib/cache/abstract-video-static-file-cache.ts)0
-rw-r--r--server/lib/files-cache/actor-follow-score-cache.ts (renamed from server/lib/cache/actor-follow-score-cache.ts)0
-rw-r--r--server/lib/files-cache/index.ts (renamed from server/lib/cache/index.ts)0
-rw-r--r--server/lib/files-cache/videos-caption-cache.ts (renamed from server/lib/cache/videos-caption-cache.ts)4
-rw-r--r--server/lib/files-cache/videos-preview-cache.ts (renamed from server/lib/cache/videos-preview-cache.ts)4
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-broadcast.ts3
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-unicast.ts2
-rw-r--r--server/lib/oauth-model.ts12
-rw-r--r--server/lib/schedulers/actor-follow-scheduler.ts2
9 files changed, 16 insertions, 11 deletions
diff --git a/server/lib/cache/abstract-video-static-file-cache.ts b/server/lib/files-cache/abstract-video-static-file-cache.ts
index 7512f2b9d..7512f2b9d 100644
--- a/server/lib/cache/abstract-video-static-file-cache.ts
+++ b/server/lib/files-cache/abstract-video-static-file-cache.ts
diff --git a/server/lib/cache/actor-follow-score-cache.ts b/server/lib/files-cache/actor-follow-score-cache.ts
index d070bde09..d070bde09 100644
--- a/server/lib/cache/actor-follow-score-cache.ts
+++ b/server/lib/files-cache/actor-follow-score-cache.ts
diff --git a/server/lib/cache/index.ts b/server/lib/files-cache/index.ts
index e921d04a7..e921d04a7 100644
--- a/server/lib/cache/index.ts
+++ b/server/lib/files-cache/index.ts
diff --git a/server/lib/cache/videos-caption-cache.ts b/server/lib/files-cache/videos-caption-cache.ts
index f240affbc..fe5b441af 100644
--- a/server/lib/cache/videos-caption-cache.ts
+++ b/server/lib/files-cache/videos-caption-cache.ts
@@ -1,5 +1,5 @@
1import { join } from 'path' 1import { join } from 'path'
2import { CACHE, CONFIG } from '../../initializers' 2import { FILES_CACHE, CONFIG } from '../../initializers'
3import { VideoModel } from '../../models/video/video' 3import { VideoModel } from '../../models/video/video'
4import { VideoCaptionModel } from '../../models/video/video-caption' 4import { VideoCaptionModel } from '../../models/video/video-caption'
5import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' 5import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
@@ -42,7 +42,7 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache <GetPathParam> {
42 if (!video) return undefined 42 if (!video) return undefined
43 43
44 const remoteStaticPath = videoCaption.getCaptionStaticPath() 44 const remoteStaticPath = videoCaption.getCaptionStaticPath()
45 const destPath = join(CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName()) 45 const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName())
46 46
47 return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) 47 return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath)
48 } 48 }
diff --git a/server/lib/cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts
index a5d6f5b62..01cd3647e 100644
--- a/server/lib/cache/videos-preview-cache.ts
+++ b/server/lib/files-cache/videos-preview-cache.ts
@@ -1,5 +1,5 @@
1import { join } from 'path' 1import { join } from 'path'
2import { CACHE, CONFIG, STATIC_PATHS } from '../../initializers' 2import { FILES_CACHE, CONFIG, STATIC_PATHS } from '../../initializers'
3import { VideoModel } from '../../models/video/video' 3import { VideoModel } from '../../models/video/video'
4import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' 4import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
5 5
@@ -31,7 +31,7 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
31 if (video.isOwned()) throw new Error('Cannot load remote preview of owned video.') 31 if (video.isOwned()) throw new Error('Cannot load remote preview of owned video.')
32 32
33 const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) 33 const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreviewName())
34 const destPath = join(CACHE.PREVIEWS.DIRECTORY, video.getPreviewName()) 34 const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, video.getPreviewName())
35 35
36 return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) 36 return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath)
37 } 37 }
diff --git a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
index 9493945ff..2b1e21c39 100644
--- a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
+++ b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
@@ -2,10 +2,9 @@ import * as Bull from 'bull'
2import * as Bluebird from 'bluebird' 2import * as Bluebird from 'bluebird'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { doRequest } from '../../../helpers/requests' 4import { doRequest } from '../../../helpers/requests'
5import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
6import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' 5import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
7import { BROADCAST_CONCURRENCY, JOB_REQUEST_TIMEOUT } from '../../../initializers' 6import { BROADCAST_CONCURRENCY, JOB_REQUEST_TIMEOUT } from '../../../initializers'
8import { ActorFollowScoreCache } from '../../cache' 7import { ActorFollowScoreCache } from '../../files-cache'
9 8
10export type ActivitypubHttpBroadcastPayload = { 9export type ActivitypubHttpBroadcastPayload = {
11 uris: string[] 10 uris: string[]
diff --git a/server/lib/job-queue/handlers/activitypub-http-unicast.ts b/server/lib/job-queue/handlers/activitypub-http-unicast.ts
index 3973dcdc8..59de7119a 100644
--- a/server/lib/job-queue/handlers/activitypub-http-unicast.ts
+++ b/server/lib/job-queue/handlers/activitypub-http-unicast.ts
@@ -3,7 +3,7 @@ import { logger } from '../../../helpers/logger'
3import { doRequest } from '../../../helpers/requests' 3import { doRequest } from '../../../helpers/requests'
4import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' 4import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
5import { JOB_REQUEST_TIMEOUT } from '../../../initializers' 5import { JOB_REQUEST_TIMEOUT } from '../../../initializers'
6import { ActorFollowScoreCache } from '../../cache' 6import { ActorFollowScoreCache } from '../../files-cache'
7 7
8export type ActivitypubHttpUnicastPayload = { 8export type ActivitypubHttpUnicastPayload = {
9 uri: string 9 uri: string
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts
index 2cd2ae97c..5b4a2bcf9 100644
--- a/server/lib/oauth-model.ts
+++ b/server/lib/oauth-model.ts
@@ -4,12 +4,12 @@ import { logger } from '../helpers/logger'
4import { UserModel } from '../models/account/user' 4import { UserModel } from '../models/account/user'
5import { OAuthClientModel } from '../models/oauth/oauth-client' 5import { OAuthClientModel } from '../models/oauth/oauth-client'
6import { OAuthTokenModel } from '../models/oauth/oauth-token' 6import { OAuthTokenModel } from '../models/oauth/oauth-token'
7import { CONFIG } from '../initializers/constants' 7import { CONFIG, CACHE } from '../initializers/constants'
8import { Transaction } from 'sequelize' 8import { Transaction } from 'sequelize'
9 9
10type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date } 10type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date }
11const accessTokenCache: { [ accessToken: string ]: OAuthTokenModel } = {} 11let accessTokenCache: { [ accessToken: string ]: OAuthTokenModel } = {}
12const userHavingToken: { [ userId: number ]: string } = {} 12let userHavingToken: { [ userId: number ]: string } = {}
13 13
14// --------------------------------------------------------------------------- 14// ---------------------------------------------------------------------------
15 15
@@ -43,6 +43,12 @@ function getAccessToken (bearerToken: string) {
43 return OAuthTokenModel.getByTokenAndPopulateUser(bearerToken) 43 return OAuthTokenModel.getByTokenAndPopulateUser(bearerToken)
44 .then(tokenModel => { 44 .then(tokenModel => {
45 if (tokenModel) { 45 if (tokenModel) {
46 // Reinit our cache
47 if (Object.keys(accessTokenCache).length > CACHE.USER_TOKENS.MAX_SIZE) {
48 accessTokenCache = {}
49 userHavingToken = {}
50 }
51
46 accessTokenCache[ bearerToken ] = tokenModel 52 accessTokenCache[ bearerToken ] = tokenModel
47 userHavingToken[ tokenModel.userId ] = tokenModel.accessToken 53 userHavingToken[ tokenModel.userId ] = tokenModel.accessToken
48 } 54 }
diff --git a/server/lib/schedulers/actor-follow-scheduler.ts b/server/lib/schedulers/actor-follow-scheduler.ts
index 3967be7f8..05e6bd139 100644
--- a/server/lib/schedulers/actor-follow-scheduler.ts
+++ b/server/lib/schedulers/actor-follow-scheduler.ts
@@ -3,7 +3,7 @@ import { logger } from '../../helpers/logger'
3import { ActorFollowModel } from '../../models/activitypub/actor-follow' 3import { ActorFollowModel } from '../../models/activitypub/actor-follow'
4import { AbstractScheduler } from './abstract-scheduler' 4import { AbstractScheduler } from './abstract-scheduler'
5import { SCHEDULER_INTERVALS_MS } from '../../initializers' 5import { SCHEDULER_INTERVALS_MS } from '../../initializers'
6import { ActorFollowScoreCache } from '../cache' 6import { ActorFollowScoreCache } from '../files-cache'
7 7
8export class ActorFollowScheduler extends AbstractScheduler { 8export class ActorFollowScheduler extends AbstractScheduler {
9 9