Log elapsed time for user delete

This commit is contained in:
Rory&
2025-12-13 02:44:12 +01:00
parent e6d22ccc47
commit 5de70ca2c8
2 changed files with 30 additions and 1 deletions
+17 -1
View File
@@ -17,7 +17,21 @@
*/
import { route } from "@spacebar/api";
import { Channel, ChannelDeleteEvent, ChannelRecipientRemoveEvent, emitEvent, Emoji, Guild, InstanceBan, Member, Recipient, Sticker, User, UserDeleteEvent } from "@spacebar/util";
import {
Channel,
ChannelDeleteEvent,
ChannelRecipientRemoveEvent,
emitEvent,
Emoji,
Guild,
InstanceBan,
Member,
Recipient,
Sticker,
Stopwatch,
User,
UserDeleteEvent,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { ChannelType, InstanceUserDeleteSchema, PrivateUserProjection } from "@spacebar/schemas";
import { Not } from "typeorm";
@@ -40,6 +54,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const sw = Stopwatch.startNew();
const body = req.body as InstanceUserDeleteSchema | undefined;
const user = await User.findOneOrFail({
where: { id: req.params.user_id },
@@ -170,6 +185,7 @@ router.post(
data: { user_id: req.params.user_id },
} as UserDeleteEvent);
console.log(`[Instance ban] Deleted user ${user.id} from instance in ${sw.elapsed().toString()} ms`);
res.sendStatus(204);
},
);
+13
View File
@@ -68,4 +68,17 @@ export class ElapsedTime {
get days(): number {
return this.totalDays;
}
toString(): string {
// Format: "DD.HH:MM:SS.mmmuuuNNN", with days being optional
const daysPart = this.days > 0 ? `${this.days}.` : "";
const hoursPart = this.hours.toString().padStart(2, "0");
const minutesPart = this.minutes.toString().padStart(2, "0");
const secondsPart = this.seconds.toString().padStart(2, "0");
const millisecondsPart = this.milliseconds.toString().padStart(3, "0");
const microsecondsPart = this.microseconds.toString().padStart(3, "0");
const nanosecondsPart = this.nanoseconds.toString().padStart(3, "0");
return `${daysPart}${hoursPart}:${minutesPart}:${secondsPart}.${millisecondsPart}${microsecondsPart}${nanosecondsPart}`;
}
}