Merge pull request #3491 from omnivore-app/fix/dont-sync-readingtime-too-soon

Only sync reading times if they are more than a minute old
This commit is contained in:
Jackson Harper 2024-02-03 09:09:52 +08:00 committed by GitHub
commit 9102fc9ae4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -18,4 +18,7 @@ export const appDataSource = new DataSource({
logger: new CustomTypeOrmLogger(['query', 'info']),
connectTimeoutMS: 40000, // 40 seconds
maxQueryExecutionTime: 10000, // 10 seconds
extra: {
options: process.env.PG_EXTRA_OPTIONS,
},
})

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,