Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: post announce logic to save to separate zset instead of to …
…topic events, closes #12536
- Loading branch information
Showing
4 changed files
with
100 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const db = require('../../database'); | ||
const batch = require('../../batch'); | ||
const topics = require('../../topics'); | ||
|
||
module.exports = { | ||
name: 'Save ActivityPub Announces in their own per-post sorted set', | ||
timestamp: Date.UTC(2024, 4, 1), | ||
method: async function () { | ||
const { progress } = this; | ||
const bulkOp = []; | ||
|
||
await batch.processSortedSet('topics:tid', async (tids, next) => { | ||
await Promise.all(tids.map(async (tid) => { | ||
const announces = await topics.events.find(tid, { | ||
type: 'announce', | ||
}); | ||
|
||
if (announces.length) { | ||
await Promise.all(announces.map(async (eid) => { | ||
const event = await db.getObject(`topicEvent:${eid}`); | ||
if (['uid', 'pid', 'timestamp'].every(prop => event.hasOwnProperty(prop))) { | ||
bulkOp.push([`pid:${event.pid}:announces`, event.timestamp, event.uid]); | ||
} | ||
})); | ||
|
||
console.log('piurging', tid); | ||
await topics.events.purge(tid, announces); | ||
} | ||
})); | ||
|
||
progress.incr(tids.length); | ||
}, { progress }); | ||
|
||
await db.sortedSetAddBulk(bulkOp); | ||
}, | ||
}; |