|
|
@ -491,7 +491,10 @@ export class UtilsService { |
|
|
|
per_page: string; |
|
|
|
per_page: string; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const cacheKey = `${CacheScope.PRODUCT_FEED}:${type}:${page}:${per_page}`; |
|
|
|
const perPage = Math.min(Math.max(parseInt(per_page, 10) || 10, 1), 100); |
|
|
|
|
|
|
|
const pageNum = Math.max(parseInt(page, 10) || 1, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cacheKey = `${CacheScope.PRODUCT_FEED}:${type}:${pageNum}:${perPage}`; |
|
|
|
|
|
|
|
|
|
|
|
const cachedData = await NocoCache.get(cacheKey, 'json'); |
|
|
|
const cachedData = await NocoCache.get(cacheKey, 'json'); |
|
|
|
|
|
|
|
|
|
|
@ -500,13 +503,14 @@ export class UtilsService { |
|
|
|
return JSON.parse(cachedData); |
|
|
|
return JSON.parse(cachedData); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
this.logger.error(e?.message, e); |
|
|
|
this.logger.error(e?.message, e); |
|
|
|
|
|
|
|
await NocoCache.del(cacheKey); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let payload = null; |
|
|
|
let payload = null; |
|
|
|
if (dayjs().isAfter(this.lastSyncTime.add(3, 'hours'))) { |
|
|
|
if (dayjs().isAfter(this.lastSyncTime.add(3, 'hours'))) { |
|
|
|
this.lastSyncTime = dayjs(); |
|
|
|
|
|
|
|
payload = await T.payload(); |
|
|
|
payload = await T.payload(); |
|
|
|
|
|
|
|
this.lastSyncTime = dayjs(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let response; |
|
|
|
let response; |
|
|
@ -517,8 +521,8 @@ export class UtilsService { |
|
|
|
payload, |
|
|
|
payload, |
|
|
|
{ |
|
|
|
{ |
|
|
|
params: { |
|
|
|
params: { |
|
|
|
per_page, |
|
|
|
per_page: perPage, |
|
|
|
page, |
|
|
|
page: pageNum, |
|
|
|
type, |
|
|
|
type, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
@ -533,7 +537,7 @@ export class UtilsService { |
|
|
|
await NocoCache.setExpiring( |
|
|
|
await NocoCache.setExpiring( |
|
|
|
cacheKey, |
|
|
|
cacheKey, |
|
|
|
JSON.stringify(response.data, getCircularReplacer), |
|
|
|
JSON.stringify(response.data, getCircularReplacer), |
|
|
|
isNaN(parseInt(process.env.NC_ATTACHMENT_EXPIRE_SECONDS)) |
|
|
|
Number.isNaN(parseInt(process.env.NC_ATTACHMENT_EXPIRE_SECONDS)) |
|
|
|
? 2 * 60 * 60 |
|
|
|
? 2 * 60 * 60 |
|
|
|
: parseInt(process.env.NC_ATTACHMENT_EXPIRE_SECONDS), |
|
|
|
: parseInt(process.env.NC_ATTACHMENT_EXPIRE_SECONDS), |
|
|
|
); |
|
|
|
); |
|
|
|