Only sync reading times if they are more than a minute old

this should hopefully reduce contention with other rules running
This commit is contained in:
Jackson Harper
2024-02-02 20:41:07 +08:00
parent 2c037d6a8a
commit 9cc046e3a2

View File

@ -25,6 +25,14 @@ async function* getSyncUpdatesIterator(redis: Redis) {
return
}
const isMoreThan60SecondsOld = (iso8601String: string): boolean => {
const currentTime = new Date()
const parsedDate = new Date(iso8601String)
const timeDifferenceInSeconds =
(currentTime.getTime() - parsedDate.getTime()) / 1000
return timeDifferenceInSeconds > 60
}
const syncReadPosition = async (cacheKey: string) => {
const components = componentsForCachedReadingPositionKey(cacheKey)
const positions = components
@ -37,7 +45,9 @@ const syncReadPosition = async (cacheKey: string) => {
components &&
positions &&
positions.positionItems &&
positions.positionItems.length > 0
positions.positionItems.length > 0 &&
positions.positionItems[0].updatedAt &&
isMoreThan60SecondsOld(positions.positionItems[0].updatedAt)
) {
const position = reduceCachedReadingPositionMembers(
components.uid,