diff options
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r-- | server/models/utils.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts index 4ebd07dab..f8a71b270 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { Sequelize } from 'sequelize-typescript' | 1 | import { Sequelize } from 'sequelize-typescript' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import { ACTIVITY_PUB } from '../initializers' | ||
3 | 4 | ||
4 | type SortType = { sortModel: any, sortValue: string } | 5 | type SortType = { sortModel: any, sortValue: string } |
5 | 6 | ||
@@ -44,6 +45,14 @@ function getSortOnModel (model: any, value: string, lastSort: string[] = [ 'id', | |||
44 | return [ firstSort, lastSort ] | 45 | return [ firstSort, lastSort ] |
45 | } | 46 | } |
46 | 47 | ||
48 | function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) { | ||
49 | const now = Date.now() | ||
50 | const createdAtTime = model.createdAt.getTime() | ||
51 | const updatedAtTime = model.updatedAt.getTime() | ||
52 | |||
53 | return (now - createdAtTime) > refreshInterval && (now - updatedAtTime) > refreshInterval | ||
54 | } | ||
55 | |||
47 | function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') { | 56 | function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') { |
48 | if (validator(value) === false) { | 57 | if (validator(value) === false) { |
49 | throw new Error(`"${value}" is not a valid ${fieldName}.`) | 58 | throw new Error(`"${value}" is not a valid ${fieldName}.`) |
@@ -108,7 +117,8 @@ export { | |||
108 | throwIfNotValid, | 117 | throwIfNotValid, |
109 | buildServerIdsFollowedBy, | 118 | buildServerIdsFollowedBy, |
110 | buildTrigramSearchIndex, | 119 | buildTrigramSearchIndex, |
111 | buildWhereIdOrUUID | 120 | buildWhereIdOrUUID, |
121 | isOutdated | ||
112 | } | 122 | } |
113 | 123 | ||
114 | // --------------------------------------------------------------------------- | 124 | // --------------------------------------------------------------------------- |