diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-14 11:52:23 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-14 11:52:23 +0200 |
commit | 7348b1fd84dee869b3c36554aea6797f09d4ceed (patch) | |
tree | 46f6800a92f659dd989d0f38c1b682a61fd2315a /server/helpers/utils.ts | |
parent | 2b62cccd75e9025fb66148bcb1feea2a458ee8e4 (diff) | |
download | PeerTube-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.ts | 24 |
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 @@ | |||
1 | import { ResultList } from '../../shared' | 1 | import { ResultList } from '../../shared' |
2 | import { CONFIG } from '../initializers' | 2 | import { CONFIG } from '../initializers' |
3 | import { ActorModel } from '../models/activitypub/actor' | ||
4 | import { ApplicationModel } from '../models/application/application' | 3 | import { ApplicationModel } from '../models/application/application' |
5 | import { pseudoRandomBytesPromise, sha256 } from './core-utils' | 4 | import { pseudoRandomBytesPromise, sha256 } from './core-utils' |
6 | import { logger } from './logger' | 5 | import { logger } from './logger' |
7 | import { join } from 'path' | 6 | import { join } from 'path' |
8 | import { Instance as ParseTorrent } from 'parse-torrent' | 7 | import { Instance as ParseTorrent } from 'parse-torrent' |
9 | import { remove } from 'fs-extra' | 8 | import { remove } from 'fs-extra' |
9 | import * as memoizee from 'memoizee' | ||
10 | 10 | ||
11 | function deleteFileAsync (path: string) { | 11 | function 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 | ||
39 | async function getServerActor () { | 39 | const 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 | } | ||
54 | namespace getServerActor { | ||
55 | export let serverActor: ActorModel | ||
56 | } | ||
57 | 45 | ||
58 | function generateVideoTmpPath (target: string | ParseTorrent) { | 46 | function generateVideoTmpPath (target: string | ParseTorrent) { |
59 | const id = typeof target === 'string' ? target : target.infoHash | 47 | const id = typeof target === 'string' ? target : target.infoHash |