set local interaction flag on files and notes for future use (e.g. smart cleanup)

This commit is contained in:
CGsama 2024-03-26 00:26:42 -04:00
parent 9ee7804990
commit f0bba455f3
8 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class LocalInteraction1706198251940 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "drive_file" ADD "isInteractedByLocalUser" boolean NOT NULL DEFAULT FALSE`,
);
await queryRunner.query(
`ALTER TABLE "note" ADD "isInteractedByLocalUser" boolean NOT NULL DEFAULT FALSE`,
);
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "drive_file" DROP COLUMN "isInteractedByLocalUser"`,
);
await queryRunner.query(
`ALTER TABLE "note" DROP COLUMN "isInteractedByLocalUser"`,
);
}
}

View File

@ -0,0 +1,23 @@
import { Notes, DriveFiles } from "@/models/index.js";
export async function setLocalInteraction( noteid: string ) {
const note = await Notes.findOneBy({ id: noteid });
if(note.isInteractedByLocalUser){
return;
}
await Notes.update(noteid, {isInteractedByLocalUser: true});
for (const fileid of note.fileIds) {
await DriveFiles.update(fileid, {isInteractedByLocalUser: true});
}
if(note.replyId != null){
setLocalInteraction(note.replyId);
}
if(note.renoteId != null){
setLocalInteraction(note.replyId);
}
}

View File

@ -224,4 +224,9 @@ export class DriveFile {
@JoinColumn()
public folder: DriveFolder | null;
//#endregion Relations
@Column("boolean", {
default: false,
})
public isInteractedByLocalUser: boolean;
}

View File

@ -297,6 +297,12 @@ export class Note {
comment: "The updated date of the Note.",
})
public updatedAt: Date | null;
@Column("boolean", {
default: false,
})
public isInteractedByLocalUser: boolean;
//#endregion
constructor(data: Partial<Note>) {

View File

@ -18,6 +18,7 @@ import define from "@/server/api/define.js";
import { HOUR } from "@/const.js";
import { getNote } from "@/server/api/common/getters.js";
import { langmap } from "@/misc/langmap.js";
import { setLocalInteraction } from "@/misc/set-local-interaction.js";
export const meta = {
tags: ["notes"],
@ -240,6 +241,7 @@ export default define(meta, paramDef, async (ps, user) => {
throw new ApiError(meta.errors.youHaveBeenBlocked);
}
}
setLocalInteraction(ps.renoteId);
}
let reply: Note | null = null;
@ -267,6 +269,7 @@ export default define(meta, paramDef, async (ps, user) => {
throw new ApiError(meta.errors.youHaveBeenBlocked);
}
}
setLocalInteraction(ps.replyId);
}
if (ps.poll) {
@ -313,6 +316,8 @@ export default define(meta, paramDef, async (ps, user) => {
apEmojis: ps.noExtractEmojis ? [] : undefined,
});
setLocalInteraction(note.id);
return {
createdNote: await Notes.pack(note, user),
};

View File

@ -3,6 +3,7 @@ import { genId } from "@/misc/gen-id.js";
import define from "@/server/api/define.js";
import { ApiError } from "@/server/api/error.js";
import { getNote } from "@/server/api/common/getters.js";
import { setLocalInteraction } from "@/misc/set-local-interaction.js";
export const meta = {
tags: ["notes", "favorites"],
@ -61,4 +62,5 @@ export default define(meta, paramDef, async (ps, user) => {
noteId: note.id,
userId: user.id,
});
setLocalInteraction(note.id);
});

View File

@ -16,6 +16,7 @@ import { genId } from "@/misc/gen-id.js";
import { getNote } from "@/server/api/common/getters.js";
import { ApiError } from "@/server/api/error.js";
import define from "@/server/api/define.js";
import { setLocalInteraction } from "@/misc/set-local-interaction.js";
export const meta = {
tags: ["notes"],
@ -177,4 +178,5 @@ export default define(meta, paramDef, async (ps, user) => {
pollOwner.inbox,
);
}
setLocalInteraction(note.id);
});

View File

@ -2,6 +2,7 @@ import createReaction from "@/services/note/reaction/create.js";
import define from "@/server/api/define.js";
import { getNote } from "@/server/api/common/getters.js";
import { ApiError } from "@/server/api/error.js";
import { setLocalInteraction } from "@/misc/set-local-interaction.js";
export const meta = {
tags: ["reactions", "notes"],
@ -60,5 +61,6 @@ export default define(meta, paramDef, async (ps, user) => {
throw new ApiError(meta.errors.youHaveBeenBlocked);
throw e;
});
setLocalInteraction(ps.noteId);
return;
});