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; public carefulBot: boolean;
@Column("boolean", {
default: true,
})
public injectFeaturedNote: boolean;
@Column("boolean", { @Column("boolean", {
default: true, default: true,
}) })

View File

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

View File

@ -359,11 +359,6 @@ export const packedMeDetailedOnlySchema = {
optional: false, optional: false,
format: "id", format: "id",
}, },
injectFeaturedNote: {
type: "boolean",
nullable: true,
optional: false,
},
receiveAnnouncementEmail: { receiveAnnouncementEmail: {
type: "boolean", type: "boolean",
nullable: true, nullable: true,
@ -434,11 +429,6 @@ export const packedMeDetailedOnlySchema = {
nullable: false, nullable: false,
optional: false, optional: false,
}, },
hasUnreadChannel: {
type: "boolean",
nullable: false,
optional: false,
},
hasUnreadNotification: { hasUnreadNotification: {
type: "boolean", type: "boolean",
nullable: false, 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, alwaysMarkNsfw: profile.alwaysMarkNsfw,
autoSensitive: profile.autoSensitive, autoSensitive: profile.autoSensitive,
carefulBot: profile.carefulBot, carefulBot: profile.carefulBot,
injectFeaturedNote: profile.injectFeaturedNote,
receiveAnnouncementEmail: profile.receiveAnnouncementEmail, receiveAnnouncementEmail: profile.receiveAnnouncementEmail,
mutedWords: profile.mutedWords, mutedWords: profile.mutedWords,
mutedInstances: profile.mutedInstances, mutedInstances: profile.mutedInstances,

View File

@ -1,18 +1,18 @@
import RE2 from "re2"; import RE2 from "re2";
import * as mfm from "mfm-js"; import * as mfm from "mfm-js";
import { publishMainStream, publishUserEvent } from "@/services/stream.js"; import {publishMainStream, publishUserEvent} from "@/services/stream.js";
import acceptAllFollowRequests from "@/services/following/requests/accept-all.js"; import acceptAllFollowRequests from "@/services/following/requests/accept-all.js";
import { publishToFollowers } from "@/services/i/update.js"; import {publishToFollowers} from "@/services/i/update.js";
import { extractCustomEmojisFromMfm } from "@/misc/extract-custom-emojis-from-mfm.js"; import {extractCustomEmojisFromMfm} from "@/misc/extract-custom-emojis-from-mfm.js";
import { extractHashtags } from "@/misc/extract-hashtags.js"; import {extractHashtags} from "@/misc/extract-hashtags.js";
import { updateUsertags } from "@/services/update-hashtag.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 {User} from "@/models/entities/user.js";
import type { UserProfile } from "@/models/entities/user-profile.js"; import type {UserProfile} from "@/models/entities/user-profile.js";
import { notificationTypes } from "@/types.js"; import {notificationTypes} from "@/types.js";
import { normalizeForSearch } from "@/misc/normalize-for-search.js"; import {normalizeForSearch} from "@/misc/normalize-for-search.js";
import { langmap } from "@/misc/langmap.js"; import {langmap} from "@/misc/langmap.js";
import { ApiError } from "../../error.js"; import {ApiError} from "../../error.js";
import define from "../../define.js"; import define from "../../define.js";
export const meta = { export const meta = {
@ -106,7 +106,6 @@ export const paramDef = {
isBot: { type: "boolean" }, isBot: { type: "boolean" },
isCat: { type: "boolean" }, isCat: { type: "boolean" },
speakAsCat: { type: "boolean" }, speakAsCat: { type: "boolean" },
injectFeaturedNote: { type: "boolean" },
receiveAnnouncementEmail: { type: "boolean" }, receiveAnnouncementEmail: { type: "boolean" },
alwaysMarkNsfw: { type: "boolean" }, alwaysMarkNsfw: { type: "boolean" },
autoSensitive: { type: "boolean" }, autoSensitive: { type: "boolean" },
@ -193,8 +192,6 @@ export default define(meta, paramDef, async (ps, _user, token) => {
profileUpdates.preventAiLearning = ps.preventAiLearning; profileUpdates.preventAiLearning = ps.preventAiLearning;
if (typeof ps.isCat === "boolean") updates.isCat = ps.isCat; if (typeof ps.isCat === "boolean") updates.isCat = ps.isCat;
if (typeof ps.speakAsCat === "boolean") updates.speakAsCat = ps.speakAsCat; if (typeof ps.speakAsCat === "boolean") updates.speakAsCat = ps.speakAsCat;
if (typeof ps.injectFeaturedNote === "boolean")
profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
if (typeof ps.receiveAnnouncementEmail === "boolean") if (typeof ps.receiveAnnouncementEmail === "boolean")
profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail; profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail;
if (typeof ps.alwaysMarkNsfw === "boolean") if (typeof ps.alwaysMarkNsfw === "boolean")

View File

@ -1,39 +1,29 @@
import * as fs from "node:fs"; import * as fs from "node:fs";
import { v4 as uuid } from "uuid"; import {v4 as uuid} from "uuid";
import type S3 from "aws-sdk/clients/s3.js"; import type S3 from "aws-sdk/clients/s3.js";
import sharp from "sharp"; import sharp from "sharp";
import { IsNull } from "typeorm"; 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 {fetchMeta} from "@/misc/fetch-meta.js";
import { contentDisposition } from "@/misc/content-disposition.js"; import {contentDisposition} from "@/misc/content-disposition.js";
import { getFileInfo } from "@/misc/get-file-info.js"; import {getFileInfo} from "@/misc/get-file-info.js";
import { import {DriveFiles, DriveFolders, UserProfiles, Users,} from "@/models/index.js";
DriveFiles, import {DriveFile} from "@/models/entities/drive-file.js";
DriveFolders, import type {IRemoteUser, User} from "@/models/entities/user.js";
Users, import {driveChart, instanceChart, perUserDriveChart,} from "@/services/chart/index.js";
Instances, import {genId} from "@/misc/gen-id.js";
UserProfiles, import {isDuplicateKeyValueError} from "@/misc/is-duplicate-key-value-error.js";
} from "@/models/index.js"; import {FILE_TYPE_BROWSERSAFE} from "@/const.js";
import { DriveFile } from "@/models/entities/drive-file.js"; import {IdentifiableError} from "@/misc/identifiable-error.js";
import type { IRemoteUser, User } from "@/models/entities/user.js"; import {getS3} from "./s3.js";
import { import {InternalStorage} from "./internal-storage.js";
driveChart, import type {IImage} from "./image-processor.js";
perUserDriveChart, import {convertSharpToWebp} from "./image-processor.js";
instanceChart, import {driveLogger} from "./logger.js";
} from "@/services/chart/index.js"; import {GenerateVideoThumbnail} from "./generate-video-thumbnail.js";
import { genId } from "@/misc/gen-id.js"; import {deleteFile} from "./delete-file.js";
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
import { IdentifiableError } from "@/misc/identifiable-error.js";
import { getS3 } from "./s3.js";
import { InternalStorage } from "./internal-storage.js";
import type { IImage } from "./image-processor.js";
import { convertSharpToWebp } from "./image-processor.js";
import { driveLogger } from "./logger.js";
import { GenerateVideoThumbnail } from "./generate-video-thumbnail.js";
import { deleteFile } from "./delete-file.js";
const logger = driveLogger.createSubLogger("register", "yellow"); const logger = driveLogger.createSubLogger("register", "yellow");