mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-28 06:08:13 -05:00
Routine to delete old friend requests
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { sub } from "date-fns";
|
||||
import { type SelectQueryBuilder, sql } from "kysely";
|
||||
import { db } from "~/db/sql";
|
||||
import type { DB } from "~/db/tables";
|
||||
import { actorId } from "~/features/auth/core/user.server";
|
||||
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
import { commonUserSelect, customAvatarUrl } from "~/utils/kysely.server";
|
||||
import { FRIEND } from "./friends-constants";
|
||||
|
||||
export async function findByUserIdWithActivity(userId: number) {
|
||||
const [friendRows, teamMemberRows] = await Promise.all([
|
||||
@@ -163,6 +165,19 @@ export async function deleteFriendRequest({
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function deleteOldPendingRequests() {
|
||||
return db
|
||||
.deleteFrom("FriendRequest")
|
||||
.where(
|
||||
"FriendRequest.createdAt",
|
||||
"<",
|
||||
dateToDatabaseTimestamp(
|
||||
sub(new Date(), { months: FRIEND.PENDING_REQUEST_EXPIRES_IN_MONTHS }),
|
||||
),
|
||||
)
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
export async function findFriendRequestBetween({
|
||||
senderId,
|
||||
receiverId,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export const FRIEND = {
|
||||
MAX_PENDING_REQUESTS: 20,
|
||||
PENDING_REQUEST_EXPIRES_IN_MONTHS: 1,
|
||||
} as const;
|
||||
|
||||
export const SENDOUQ_ACTIVITY_LABEL = "SendouQ";
|
||||
|
||||
12
app/routines/deleteOldPendingFriendRequests.ts
Normal file
12
app/routines/deleteOldPendingFriendRequests.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as FriendRepository from "../features/friends/FriendRepository.server";
|
||||
import { logger } from "../utils/logger";
|
||||
import { Routine } from "./routine.server";
|
||||
|
||||
export const DeleteOldPendingFriendRequestsRoutine = new Routine({
|
||||
name: "DeleteOldPendingFriendRequests",
|
||||
func: async () => {
|
||||
const { numDeletedRows } =
|
||||
await FriendRepository.deleteOldPendingRequests();
|
||||
logger.info(`Deleted ${numDeletedRows} old pending friend requests`);
|
||||
},
|
||||
});
|
||||
@@ -3,6 +3,7 @@ import { CloseExpiredContinueVotesRoutine } from "./closeExpiredContinueVotes";
|
||||
import { DeleteObsoleteMatchVodsRoutine } from "./deleteObsoleteMatchVods";
|
||||
import { DeleteOldExternalStreamsRoutine } from "./deleteOldExternalStreams";
|
||||
import { DeleteOldNotificationsRoutine } from "./deleteOldNotifications";
|
||||
import { DeleteOldPendingFriendRequestsRoutine } from "./deleteOldPendingFriendRequests";
|
||||
import { DeleteOldTournamentAuditLogsRoutine } from "./deleteOldTournamentAuditLogs";
|
||||
import { DeleteOrphanArtTagsRoutine } from "./deleteOrphanArtTags";
|
||||
import { NotifyCheckInStartRoutine } from "./notifyCheckInStart";
|
||||
@@ -38,6 +39,7 @@ export const everyHourAt30 = [
|
||||
export const daily = [
|
||||
DeleteObsoleteMatchVodsRoutine,
|
||||
DeleteOldNotificationsRoutine,
|
||||
DeleteOldPendingFriendRequestsRoutine,
|
||||
DeleteOldTournamentAuditLogsRoutine,
|
||||
CloseExpiredCommissionsRoutine,
|
||||
DeleteOrphanArtTagsRoutine,
|
||||
|
||||
Reference in New Issue
Block a user