mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
ttl/pttl (#8689)
This commit is contained in:
@@ -210,4 +210,26 @@ UPDATE "legacy_object"
|
||||
module.pexpireAt = async function (key, timestamp) {
|
||||
await doExpire(key, new Date(timestamp));
|
||||
};
|
||||
|
||||
async function getExpire(key) {
|
||||
const res = await module.pool.query({
|
||||
name: 'ttl',
|
||||
text: `
|
||||
SELECT "expireAt"::TEXT
|
||||
FROM "legacy_object"
|
||||
WHERE "_key" = $1::TEXT
|
||||
LIMIT 1`,
|
||||
values: [key],
|
||||
});
|
||||
|
||||
return res.rows.length ? new Date(res.rows[0].expireAt).getTime() : null;
|
||||
}
|
||||
|
||||
module.ttl = async function (key) {
|
||||
return Math.round((await getExpire(key) - Date.now()) / 1000);
|
||||
};
|
||||
|
||||
module.pttl = async function (key) {
|
||||
return await getExpire(key) - Date.now();
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user