Merge pull request #24367 from overleaf/bg-add-new-project-history-flush-script

add new project history flush script

GitOrigin-RevId: 4d6f3be1ada7191334b934e34e1c9eac59a816d0
This commit is contained in:
Brian Gough
2025-03-24 10:46:34 +00:00
committed by Copybot
parent 8ada51158f
commit 31b57e2991
5 changed files with 219 additions and 0 deletions
@@ -298,6 +298,26 @@ async function getFirstOpTimestamp(projectId) {
return firstOpTimestamp
}
async function getFirstOpTimestamps(projectIds) {
const keys = projectIds.map(projectId =>
Keys.projectHistoryFirstOpTimestamp({ project_id: projectId })
)
const results = await rclient.mget(keys)
const timestamps = results.map(result => {
// convert stored time back to a numeric timestamp
const timestamp = parseInt(result, 10)
// check for invalid timestamp
if (isNaN(timestamp)) {
return null
}
// convert numeric timestamp to a date object
return new Date(timestamp)
})
return timestamps
}
async function clearFirstOpTimestamp(projectId) {
const key = Keys.projectHistoryFirstOpTimestamp({ project_id: projectId })
await rclient.del(key)
@@ -357,6 +377,7 @@ const getProjectIdsWithHistoryOpsCountCb = callbackify(
)
const setFirstOpTimestampCb = callbackify(setFirstOpTimestamp)
const getFirstOpTimestampCb = callbackify(getFirstOpTimestamp)
const getFirstOpTimestampsCb = callbackify(getFirstOpTimestamps)
const clearFirstOpTimestampCb = callbackify(clearFirstOpTimestamp)
const getProjectIdsWithFirstOpTimestampsCb = callbackify(
getProjectIdsWithFirstOpTimestamps
@@ -394,6 +415,7 @@ export {
getProjectIdsWithHistoryOpsCountCb as getProjectIdsWithHistoryOpsCount,
setFirstOpTimestampCb as setFirstOpTimestamp,
getFirstOpTimestampCb as getFirstOpTimestamp,
getFirstOpTimestampsCb as getFirstOpTimestamps,
clearFirstOpTimestampCb as clearFirstOpTimestamp,
getProjectIdsWithFirstOpTimestampsCb as getProjectIdsWithFirstOpTimestamps,
clearDanglingFirstOpTimestampCb as clearDanglingFirstOpTimestamp,
@@ -413,6 +435,7 @@ export const promises = {
getProjectIdsWithHistoryOpsCount,
setFirstOpTimestamp,
getFirstOpTimestamp,
getFirstOpTimestamps,
clearFirstOpTimestamp,
getProjectIdsWithFirstOpTimestamps,
clearDanglingFirstOpTimestamp,