Removed the featured note injection dead code
ci/woodpecker/push/ociImageTag Pipeline was successful Details

This commit is contained in:
Natty 2023-08-06 16:28:13 +02:00
parent 0409015c96
commit a1d47e709a
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
8 changed files with 33 additions and 152 deletions

View File

@ -179,11 +179,6 @@ export class UserProfile {
})
public carefulBot: boolean;
@Column("boolean", {
default: true,
})
public injectFeaturedNote: boolean;
@Column("boolean", {
default: true,
})

View File

@ -480,7 +480,6 @@ export const UserRepository = db.getRepository(User).extend({
? {
avatarId: user.avatarId,
bannerId: user.bannerId,
injectFeaturedNote: profile!.injectFeaturedNote,
receiveAnnouncementEmail: profile!.receiveAnnouncementEmail,
alwaysMarkNsfw: profile!.alwaysMarkNsfw,
autoSensitive: profile!.autoSensitive,

View File

@ -359,11 +359,6 @@ export const packedMeDetailedOnlySchema = {
optional: false,
format: "id",
},
injectFeaturedNote: {
type: "boolean",
nullable: true,
optional: false,
},
receiveAnnouncementEmail: {
type: "boolean",
nullable: true,
@ -434,11 +429,6 @@ export const packedMeDetailedOnlySchema = {
nullable: false,
optional: false,
},
hasUnreadChannel: {
type: "boolean",
nullable: false,
optional: false,
},
hasUnreadNotification: {
type: "boolean",
nullable: false,

View File

@ -1,53 +0,0 @@
import rndstr from "rndstr";
import type { Note } from "@/models/entities/note.js";
import type { User } from "@/models/entities/user.js";
import { Notes, UserProfiles, NoteReactions } from "@/models/index.js";
import { generateMutedUserQuery } from "./generate-muted-user-query.js";
import { generateBlockedUserQuery } from "./generate-block-query.js";
// TODO: リアクション、Renote、返信などをしたートは除外する
export async function injectFeatured(timeline: Note[], user?: User | null) {
if (timeline.length < 5) return;
if (user) {
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
if (!profile.injectFeaturedNote) return;
}
const max = 30;
const day = 1000 * 60 * 60 * 24 * 3; // 3日前まで
const query = Notes.createQueryBuilder("note")
.addSelect("note.score")
.where("note.userHost IS NULL")
.andWhere("note.score > 0")
.andWhere("note.createdAt > :date", { date: new Date(Date.now() - day) })
.andWhere(`note.visibility = 'public'`)
.innerJoinAndSelect("note.user", "user");
if (user) {
query.andWhere("note.userId != :userId", { userId: user.id });
generateMutedUserQuery(query, user);
generateBlockedUserQuery(query, user);
const reactionQuery = NoteReactions.createQueryBuilder("reaction")
.select("reaction.noteId")
.where("reaction.userId = :userId", { userId: user.id });
query.andWhere(`note.id NOT IN (${reactionQuery.getQuery()})`);
}
const notes = await query.orderBy("note.score", "DESC").take(max).getMany();
if (notes.length === 0) return;
// Pick random one
const featured = notes[Math.floor(Math.random() * notes.length)];
(featured as any)._featuredId_ = rndstr("a-z0-9", 8);
// Inject featured
timeline.splice(3, 0, featured);
}

View File

@ -1,36 +0,0 @@
import rndstr from "rndstr";
import type { Note } from "@/models/entities/note.js";
import type { User } from "@/models/entities/user.js";
import { PromoReads, PromoNotes, Notes, Users } from "@/models/index.js";
export async function injectPromo(timeline: Note[], user?: User | null) {
if (timeline.length < 5) return;
// TODO: readやexpireフィルタはクエリ側でやる
const reads = user
? await PromoReads.findBy({
userId: user.id,
})
: [];
let promos = await PromoNotes.find();
promos = promos.filter((n) => n.expiresAt.getTime() > Date.now());
promos = promos.filter((n) => !reads.map((r) => r.noteId).includes(n.noteId));
if (promos.length === 0) return;
// Pick random promo
const promo = promos[Math.floor(Math.random() * promos.length)];
const note = await Notes.findOneByOrFail({ id: promo.noteId });
// Join
note.user = await Users.findOneByOrFail({ id: note.userId });
(note as any)._prId_ = rndstr("a-z0-9", 8);
// Inject promo
timeline.splice(3, 0, note);
}

View File

@ -57,7 +57,6 @@ export default define(meta, paramDef, async (ps, me) => {
alwaysMarkNsfw: profile.alwaysMarkNsfw,
autoSensitive: profile.autoSensitive,
carefulBot: profile.carefulBot,
injectFeaturedNote: profile.injectFeaturedNote,
receiveAnnouncementEmail: profile.receiveAnnouncementEmail,
mutedWords: profile.mutedWords,
mutedInstances: profile.mutedInstances,

View File

@ -6,7 +6,7 @@ import { publishToFollowers } from "@/services/i/update.js";
import {extractCustomEmojisFromMfm} from "@/misc/extract-custom-emojis-from-mfm.js";
import {extractHashtags} from "@/misc/extract-hashtags.js";
import {updateUsertags} from "@/services/update-hashtag.js";
import { Users, DriveFiles, UserProfiles, Pages } from "@/models/index.js";
import {DriveFiles, Pages, UserProfiles, Users} from "@/models/index.js";
import type {User} from "@/models/entities/user.js";
import type {UserProfile} from "@/models/entities/user-profile.js";
import {notificationTypes} from "@/types.js";
@ -106,7 +106,6 @@ export const paramDef = {
isBot: { type: "boolean" },
isCat: { type: "boolean" },
speakAsCat: { type: "boolean" },
injectFeaturedNote: { type: "boolean" },
receiveAnnouncementEmail: { type: "boolean" },
alwaysMarkNsfw: { type: "boolean" },
autoSensitive: { type: "boolean" },
@ -193,8 +192,6 @@ export default define(meta, paramDef, async (ps, _user, token) => {
profileUpdates.preventAiLearning = ps.preventAiLearning;
if (typeof ps.isCat === "boolean") updates.isCat = ps.isCat;
if (typeof ps.speakAsCat === "boolean") updates.speakAsCat = ps.speakAsCat;
if (typeof ps.injectFeaturedNote === "boolean")
profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
if (typeof ps.receiveAnnouncementEmail === "boolean")
profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail;
if (typeof ps.alwaysMarkNsfw === "boolean")

View File

@ -5,24 +5,14 @@ import { v4 as uuid } from "uuid";
import type S3 from "aws-sdk/clients/s3.js";
import sharp from "sharp";
import {IsNull} from "typeorm";
import { publishMainStream, publishDriveStream } from "@/services/stream.js";
import {publishDriveStream, publishMainStream} from "@/services/stream.js";
import {fetchMeta} from "@/misc/fetch-meta.js";
import {contentDisposition} from "@/misc/content-disposition.js";
import {getFileInfo} from "@/misc/get-file-info.js";
import {
DriveFiles,
DriveFolders,
Users,
Instances,
UserProfiles,
} from "@/models/index.js";
import {DriveFiles, DriveFolders, UserProfiles, Users,} from "@/models/index.js";
import {DriveFile} from "@/models/entities/drive-file.js";
import type {IRemoteUser, User} from "@/models/entities/user.js";
import {
driveChart,
perUserDriveChart,
instanceChart,
} from "@/services/chart/index.js";
import {driveChart, instanceChart, perUserDriveChart,} from "@/services/chart/index.js";
import {genId} from "@/misc/gen-id.js";
import {isDuplicateKeyValueError} from "@/misc/is-duplicate-key-value-error.js";
import {FILE_TYPE_BROWSERSAFE} from "@/const.js";