Skip to content

Commit

Permalink
most-gans: minor optimisation, logger update
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed May 17, 2024
1 parent dd1b7a3 commit f979eca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions most-gans/eventstream-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { bot } from '../botbase';
import { processArticle, TABLE, db } from "./model";
import { pageFromCategoryEvent, Route } from "../eventstream-router/app";
import type {ResultSetHeader} from "mysql2";
import {NS_MAIN} from "../namespaces";

/**
* Keep the db updated with new GA promotions and demotions.
Expand Down Expand Up @@ -63,6 +64,10 @@ export default class Gans extends Route {
}

async processMove(oldTitle: string, newTitle: string) {
const oldTitleObj = bot.Title.newFromText(oldTitle);
if (oldTitleObj && oldTitleObj.getNamespaceId() !== NS_MAIN) {
return;
}
db.run(`
UPDATE ${TABLE}
SET article = ?, lastUpdate = UTC_TIMESTAMP()
Expand All @@ -85,9 +90,7 @@ export default class Gans extends Route {
WHERE nominator = ?
`, [oldUsername, newUsername]).then(result => {
const affectedRows = (result?.[0] as ResultSetHeader)?.affectedRows;
if (affectedRows > 0) {
this.log(`[+] ${oldUsername} renamed to ${newUsername}. Updated ${affectedRows} row(s).`);
}
this.log(`[+] ${oldUsername} renamed to ${newUsername}. Updated ${affectedRows} row(s).`);
}).catch(err => {
this.log(`[E] Failed processing user rename: [[User:${oldUsername}]] to [[User:${newUsername}]]`);
this.log(err);
Expand Down

0 comments on commit f979eca

Please sign in to comment.