aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts12
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 @@
1import { Sequelize } from 'sequelize-typescript' 1import { Sequelize } from 'sequelize-typescript'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { ACTIVITY_PUB } from '../initializers'
3 4
4type SortType = { sortModel: any, sortValue: string } 5type 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
48function 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
47function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') { 56function 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// ---------------------------------------------------------------------------