Embeds: factor out from postMessage

This commit is contained in:
Rory& committed 2026-03-26 11:46:48 +01:00
1 parent 47e782ad62
commit daaf6eae28
6 files changed
+202 -134

No files matched your search

@@ -24,4 +24,5 @@ export class MessageLimits {
maxBulkDelete: number = 1000;
maxEmbedDownloadSize: number = 1024 * 1024 * 5;
maxPreloadCount: number = 100;
maxEmbeds: number = 20;
}
+7
View File
@@ -29,4 +29,11 @@ export class EmbedCache extends BaseClass {
@Column({ type: "simple-json" })
embed: Embed;
// TODO: store all returned embed objects from a handler
// @Column({ type: "simple-json" })
// embeds: Embed[];
@Column({ name: "created_at", type: "timestamp with time zone" })
createdAt: Date;
}
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class EmbedCacheCreatedAt1772404321402 implements MigrationInterface {
name = "EmbedCacheCreatedAt1772404321402";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "embed_cache" ADD "created_at" timestamp with time zone DEFAULT now();`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "embed_cache" DROP COLUMN "created_at"`);
}
}
+13
View File
@@ -42,3 +42,16 @@ export function arrayDistinctBy<T, M>(array: T[], selector: (elem: T) => M): T[]
return true;
});
}
export function arrayGroupBy<T, M>(array: T[], selector: (elem: T) => M): Map<M, T[]> {
const map = new Map<M, T[]>();
array.forEach((item) => {
const mappedValue = selector(item);
const existing = map.get(mappedValue);
if (existing) existing.push(item);
else map.set(mappedValue, [item]);
});
return map;
}