aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-14 11:52:23 +0200
committerChocobozzz <me@florianbigard.com>2018-09-14 11:52:23 +0200
commit7348b1fd84dee869b3c36554aea6797f09d4ceed (patch)
tree46f6800a92f659dd989d0f38c1b682a61fd2315a /server/helpers/utils.ts
parent2b62cccd75e9025fb66148bcb1feea2a458ee8e4 (diff)
downloadPeerTube-7348b1fd84dee869b3c36554aea6797f09d4ceed.tar.gz
PeerTube-7348b1fd84dee869b3c36554aea6797f09d4ceed.tar.zst
PeerTube-7348b1fd84dee869b3c36554aea6797f09d4ceed.zip
Speed up overviews route
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r--server/helpers/utils.ts24
1 files changed, 6 insertions, 18 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index a1ed8e72d..a42474417 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -1,12 +1,12 @@
1import { ResultList } from '../../shared' 1import { ResultList } from '../../shared'
2import { CONFIG } from '../initializers' 2import { CONFIG } from '../initializers'
3import { ActorModel } from '../models/activitypub/actor'
4import { ApplicationModel } from '../models/application/application' 3import { ApplicationModel } from '../models/application/application'
5import { pseudoRandomBytesPromise, sha256 } from './core-utils' 4import { pseudoRandomBytesPromise, sha256 } from './core-utils'
6import { logger } from './logger' 5import { logger } from './logger'
7import { join } from 'path' 6import { join } from 'path'
8import { Instance as ParseTorrent } from 'parse-torrent' 7import { Instance as ParseTorrent } from 'parse-torrent'
9import { remove } from 'fs-extra' 8import { remove } from 'fs-extra'
9import * as memoizee from 'memoizee'
10 10
11function deleteFileAsync (path: string) { 11function deleteFileAsync (path: string) {
12 remove(path) 12 remove(path)
@@ -36,24 +36,12 @@ function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], obje
36 } as ResultList<U> 36 } as ResultList<U>
37} 37}
38 38
39async function getServerActor () { 39const getServerActor = memoizee(async function () {
40 if (getServerActor.serverActor === undefined) { 40 const application = await ApplicationModel.load()
41 const application = await ApplicationModel.load() 41 if (!application) throw Error('Could not load Application from database.')
42 if (!application) throw Error('Could not load Application from database.')
43 42
44 getServerActor.serverActor = application.Account.Actor 43 return application.Account.Actor
45 } 44})
46
47 if (!getServerActor.serverActor) {
48 logger.error('Cannot load server actor.')
49 process.exit(0)
50 }
51
52 return Promise.resolve(getServerActor.serverActor)
53}
54namespace getServerActor {
55 export let serverActor: ActorModel
56}
57 45
58function generateVideoTmpPath (target: string | ParseTorrent) { 46function generateVideoTmpPath (target: string | ParseTorrent) {
59 const id = typeof target === 'string' ? target : target.infoHash 47 const id = typeof target === 'string' ? target : target.infoHash