Skip to content

Commit

Permalink
add task for purging stale pages with AfC templates
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Oct 23, 2023
1 parent bed4c10 commit e0bf7c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions reports/afc-draft-purger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {enwikidb} from "../db";
import {arrayChunk} from "../utils";
import {bot, log} from "../botbase";

(async function () {

log(`[S] Started`)
const db = new enwikidb();
const [timeTaken, result] = await db.timedQuery(`
SELECT page_id FROM page
JOIN templatelinks ON tl_from = page_id
AND tl_target_id = (SELECT lt_id FROM linktarget WHERE lt_namespace = 10 AND lt_title = "AfC_submission")
JOIN revision ON rev_id = page_latest
WHERE page_namespace IN (2, 118)
AND rev_timestamp < DATE_FORMAT(UTC_DATE() - INTERVAL 5 MONTH, '%Y%m%d%H%i%S')
AND page_id NOT IN (SELECT cl_from FROM categorylinks WHERE cl_to = "AfC_G13_eligible_soon_submissions")
`);
log(`[S] Got query result in ${timeTaken.toFixed(2)} seconds: found ${result.length} pages to be purged`);
const batches = arrayChunk(result.map(row => row.page_id as number), 100);
await bot.seriesBatchOperation(batches, batch => bot.purge(batch), 10000, 2);

})();
2 changes: 1 addition & 1 deletion utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function makeSentence(list: string[]) {
return text;
}

export function arrayChunk(arr, size) {
export function arrayChunk<T>(arr: Array<T>, size: number): Array<Array<T>> {
var numChunks = Math.ceil(arr.length / size);
var result = new Array(numChunks);
for(var i = 0; i < numChunks; i++) {
Expand Down

0 comments on commit e0bf7c4

Please sign in to comment.