chore(clean): disable clean orphan

This commit is contained in:
Jo 2025-07-23 13:44:53 +02:00
parent d5f63107b9
commit a0cbf8ff4b
Signed by: devthejo
GPG key ID: 00CCA7A92B1D5351

View file

@ -105,58 +105,58 @@ module.exports = async function () {
} }
// this is temporary function (fixing actual data) // this is temporary function (fixing actual data)
async function cleanupOrphanedHotGeodata() { // async function cleanupOrphanedHotGeodata() {
// Get all devices from hot storage // // Get all devices from hot storage
const hotDevices = new Set() // const hotDevices = new Set()
let hotCursor = "0" // let hotCursor = "0"
do { // do {
// Use zscan to iterate through the sorted set // // Use zscan to iterate through the sorted set
const [newCursor, items] = await redisHot.zscan( // const [newCursor, items] = await redisHot.zscan(
HOTGEODATA_KEY, // HOTGEODATA_KEY,
hotCursor, // hotCursor,
"COUNT", // "COUNT",
"100" // "100"
) // )
hotCursor = newCursor // hotCursor = newCursor
// Extract device IDs (every other item in the result is a score) // // Extract device IDs (every other item in the result is a score)
for (let i = 0; i < items.length; i += 2) { // for (let i = 0; i < items.length; i += 2) {
hotDevices.add(items[i]) // hotDevices.add(items[i])
} // }
} while (hotCursor !== "0") // } while (hotCursor !== "0")
// Process each hot device // // Process each hot device
await async.eachLimit( // await async.eachLimit(
[...hotDevices], // [...hotDevices],
MAX_PARALLEL_PROCESS, // MAX_PARALLEL_PROCESS,
async (deviceId) => { // async (deviceId) => {
try { // try {
// Check if device exists in cold storage // // Check if device exists in cold storage
const coldKey = `${COLDGEODATA_DEVICE_KEY_PREFIX}${deviceId}` // const coldKey = `${COLDGEODATA_DEVICE_KEY_PREFIX}${deviceId}`
const exists = await redisCold.exists(coldKey) // const exists = await redisCold.exists(coldKey)
// If device doesn't exist in cold storage, remove it from hot storage // // If device doesn't exist in cold storage, remove it from hot storage
if (!exists) { // if (!exists) {
await redisHot.zrem(HOTGEODATA_KEY, deviceId) // await redisHot.zrem(HOTGEODATA_KEY, deviceId)
logger.debug( // logger.debug(
{ deviceId }, // { deviceId },
"Removed orphaned device data from hot storage (not found in cold storage)" // "Removed orphaned device data from hot storage (not found in cold storage)"
) // )
} // }
} catch (error) { // } catch (error) {
logger.error( // logger.error(
{ error, deviceId }, // { error, deviceId },
"Error checking orphaned device data" // "Error checking orphaned device data"
) // )
} // }
} // }
) // )
} // }
// Schedule both cleanup functions to run periodically // Schedule both cleanup functions to run periodically
cron.schedule(CLEANUP_CRON, async () => { cron.schedule(CLEANUP_CRON, async () => {
await cleanupOldGeodata() await cleanupOldGeodata()
await cleanupOrphanedHotGeodata() // await cleanupOrphanedHotGeodata()
}) })
} }
} }