From cab91f7c3c27946e50877f49df81bce4773e975a Mon Sep 17 00:00:00 2001 From: RoiArthurB Date: Fri, 17 Feb 2023 06:38:47 +0000 Subject: [PATCH 1/4] [DOCKER] Add vips-dev as runtime dependencies - Fix #9596 Signed-off-by: RoiArthurB --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 03ede16c7..a0325265f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ FROM node:19-alpine WORKDIR /calckey # Install runtime dependencies -RUN apk add --no-cache --no-progress tini ffmpeg +RUN apk add --no-cache --no-progress tini ffmpeg vips-dev COPY . ./ From 9469e4d3992fc90284b0c218aa870446fe8d995f Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Fri, 17 Feb 2023 00:01:22 -0800 Subject: [PATCH 2/4] perf: :zap: emoji lib performance fix --- packages/backend/src/misc/reaction-lib.ts | 87 +++++++++++------------ 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/packages/backend/src/misc/reaction-lib.ts b/packages/backend/src/misc/reaction-lib.ts index a61c0a119..7d78904bb 100644 --- a/packages/backend/src/misc/reaction-lib.ts +++ b/packages/backend/src/misc/reaction-lib.ts @@ -4,73 +4,68 @@ import { Emojis } from "@/models/index.js"; import { toPunyNullable } from "./convert-host.js"; import { IsNull } from "typeorm"; -const legacies: Record = { - like: "👍", - love: "❀", // ă“ă“ă«èš˜èż°ă™ă‚‹ć ŽćˆăŻç•°äœ“ć­—ă‚»ăƒŹă‚Żă‚żă‚’ć…„ă‚ŒăȘい <- not that good because modern browsers just display it as the red heart so just convert it to it to not end up with two seperate reactions of "the same emoji" for the user - laugh: "😆", - hmm: "đŸ€”", - surprise: "😼", - congrats: "🎉", - angry: "💱", - confused: "đŸ˜„", - rip: "😇", - pudding: "🍼", - star: "⭐", -}; +const legacies = new Map([ + ['like', '👍'], + ['love', '❀'], + ['laugh', '😆'], + ['hmm', 'đŸ€”'], + ['surprise', '😼'], + ['congrats', '🎉'], + ['angry', '💱'], + ['confused', 'đŸ˜„'], + ['rip', '😇'], + ['pudding', '🍼'], + ['star', '⭐'], +]); -export async function getFallbackReaction(): Promise { +export async function getFallbackReaction() { const meta = await fetchMeta(); return meta.defaultReaction; } export function convertLegacyReactions(reactions: Record) { - const _reactions = {} as Record; + const _reactions = new Map(); + const decodedReactions = new Map(); - for (const reaction of Object.keys(reactions)) { + for (const reaction in reactions) { if (reactions[reaction] <= 0) continue; - if (Object.keys(legacies).includes(reaction)) { - if (_reactions[legacies[reaction]]) { - _reactions[legacies[reaction]] += reactions[reaction]; - } else { - _reactions[legacies[reaction]] = reactions[reaction]; - } - } else if (reaction === "♄") { - if (_reactions["❀"]) { - _reactions["❀"] += reactions[reaction]; - } else { - _reactions["❀"] = reactions[reaction]; - } + let decodedReaction; + if (decodedReactions.has(reaction)) { + decodedReaction = decodedReactions.get(reaction); } else { - if (_reactions[reaction]) { - _reactions[reaction] += reactions[reaction]; - } else { - _reactions[reaction] = reactions[reaction]; - } + decodedReaction = decodeReaction(reaction); + decodedReactions.set(reaction, decodedReaction); + } + + let emoji = legacies.get(decodedReaction.reaction); + if (emoji) { + _reactions.set(emoji, (_reactions.get(emoji) || 0) + reactions[reaction]); + } else { + _reactions.set(reaction, (_reactions.get(reaction) || 0) + reactions[reaction]); } } - const _reactions2 = {} as Record; - - for (const reaction of Object.keys(_reactions)) { - _reactions2[decodeReaction(reaction).reaction] = _reactions[reaction]; + const _reactions2 = new Map(); + for (const [reaction, count] of _reactions) { + const decodedReaction = decodedReactions.get(reaction); + _reactions2.set(decodedReaction.reaction, count); } - return _reactions2; + return Object.fromEntries(_reactions2); } export async function toDbReaction( reaction?: string | null, reacterHost?: string | null, ): Promise { - if (reaction == null) return await getFallbackReaction(); + if (!reaction) return await getFallbackReaction(); reacterHost = toPunyNullable(reacterHost); // Convert string-type reactions to unicode - if (Object.keys(legacies).includes(reaction)) return legacies[reaction]; - // Convert old heart to new - if (reaction === "♄") return "❀"; + const emoji = legacies.get(reaction) || (reaction === "♄" ? "❀" : null); + if (emoji) return emoji; // Allow unicode reactions const match = emojiRegex.exec(reaction); @@ -83,7 +78,7 @@ export async function toDbReaction( if (custom) { const name = custom[1]; const emoji = await Emojis.findOneBy({ - host: reacterHost ?? IsNull(), + host: reacterHost || IsNull(), name, }); @@ -132,7 +127,7 @@ export function decodeReaction(str: string): DecodedReaction { } export function convertLegacyReaction(reaction: string): string { - reaction = decodeReaction(reaction).reaction; - if (Object.keys(legacies).includes(reaction)) return legacies[reaction]; - return reaction; + const decoded = decodeReaction(reaction).reaction; + if (legacies.has(decoded)) return legacies.get(decoded)!; + return decoded; } From d5508535b9eaa6d568b13e73c147faea50dbe177 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Fri, 17 Feb 2023 00:16:35 -0800 Subject: [PATCH 3/4] chore: remove hard-to-see gradient --- packages/backend/src/misc/gen-identicon.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend/src/misc/gen-identicon.ts b/packages/backend/src/misc/gen-identicon.ts index fecdb4062..1e51dfe2a 100644 --- a/packages/backend/src/misc/gen-identicon.ts +++ b/packages/backend/src/misc/gen-identicon.ts @@ -14,7 +14,6 @@ const colors = [ ["#eb6f92", "#b4637a"], ["#f6c177", "#ea9d34"], ["#ebbcba", "#d7827e"], - ["#31748f", "#286983"], ["#9ccfd8", "#56949f"], ["#c4a7e7", "#907aa9"], ["#eb6f92", "#f6c177"], From cdf9a036046ba7651c8c82bbf8e35e5ae24f4500 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Fri, 17 Feb 2023 00:19:29 -0800 Subject: [PATCH 4/4] chore: formatting --- packages/backend/src/misc/reaction-lib.ts | 33 +++++----- .../server/api/endpoints/channels/followed.ts | 16 +++-- .../src/components/global/MkPageHeader.vue | 63 ++++++++++--------- 3 files changed, 61 insertions(+), 51 deletions(-) diff --git a/packages/backend/src/misc/reaction-lib.ts b/packages/backend/src/misc/reaction-lib.ts index 7d78904bb..e25b2d661 100644 --- a/packages/backend/src/misc/reaction-lib.ts +++ b/packages/backend/src/misc/reaction-lib.ts @@ -5,17 +5,17 @@ import { toPunyNullable } from "./convert-host.js"; import { IsNull } from "typeorm"; const legacies = new Map([ - ['like', '👍'], - ['love', '❀'], - ['laugh', '😆'], - ['hmm', 'đŸ€”'], - ['surprise', '😼'], - ['congrats', '🎉'], - ['angry', '💱'], - ['confused', 'đŸ˜„'], - ['rip', '😇'], - ['pudding', '🍼'], - ['star', '⭐'], + ["like", "👍"], + ["love", "❀"], + ["laugh", "😆"], + ["hmm", "đŸ€”"], + ["surprise", "😼"], + ["congrats", "🎉"], + ["angry", "💱"], + ["confused", "đŸ˜„"], + ["rip", "😇"], + ["pudding", "🍼"], + ["star", "⭐"], ]); export async function getFallbackReaction() { @@ -42,7 +42,10 @@ export function convertLegacyReactions(reactions: Record) { if (emoji) { _reactions.set(emoji, (_reactions.get(emoji) || 0) + reactions[reaction]); } else { - _reactions.set(reaction, (_reactions.get(reaction) || 0) + reactions[reaction]); + _reactions.set( + reaction, + (_reactions.get(reaction) || 0) + reactions[reaction], + ); } } @@ -127,7 +130,7 @@ export function decodeReaction(str: string): DecodedReaction { } export function convertLegacyReaction(reaction: string): string { - const decoded = decodeReaction(reaction).reaction; - if (legacies.has(decoded)) return legacies.get(decoded)!; - return decoded; + const decoded = decodeReaction(reaction).reaction; + if (legacies.has(decoded)) return legacies.get(decoded)!; + return decoded; } diff --git a/packages/backend/src/server/api/endpoints/channels/followed.ts b/packages/backend/src/server/api/endpoints/channels/followed.ts index f9e61222f..993a211f7 100644 --- a/packages/backend/src/server/api/endpoints/channels/followed.ts +++ b/packages/backend/src/server/api/endpoints/channels/followed.ts @@ -32,17 +32,23 @@ export const paramDef = { } as const; export default define(meta, paramDef, async (ps, me) => { - const query = ChannelFollowings.createQueryBuilder('following').andWhere({ followerId: me.id }); + const query = ChannelFollowings.createQueryBuilder("following").andWhere({ + followerId: me.id, + }); if (ps.sinceId) { - query.andWhere('following."followeeId" > :sinceId', { sinceId: ps.sinceId }); + query.andWhere('following."followeeId" > :sinceId', { + sinceId: ps.sinceId, + }); } if (ps.untilId) { - query.andWhere('following."followeeId" < :untilId', { untilId: ps.untilId }); + query.andWhere('following."followeeId" < :untilId', { + untilId: ps.untilId, + }); } if (ps.sinceId && !ps.untilId) { - query.orderBy('following."followeeId"', 'ASC'); + query.orderBy('following."followeeId"', "ASC"); } else { - query.orderBy('following."followeeId"', 'DESC'); + query.orderBy('following."followeeId"', "DESC"); } const followings = await query.take(ps.limit).getMany(); diff --git a/packages/client/src/components/global/MkPageHeader.vue b/packages/client/src/components/global/MkPageHeader.vue index 8fa3edfe1..3b844bd82 100644 --- a/packages/client/src/components/global/MkPageHeader.vue +++ b/packages/client/src/components/global/MkPageHeader.vue @@ -1,35 +1,36 @@