feat(discord-gateway): replace base64 sticker cache column with image URL storage

This commit is contained in:
MythEclipse
2026-06-06 14:10:55 +07:00
parent da885339f9
commit 6a3d0eb17c
3 changed files with 21 additions and 7 deletions
@@ -0,0 +1,7 @@
-- Replace base64 blob storage with uploaded image URL
-- Old base64 data is dropped; cache will refill on next occurrence via upload+URL.
ALTER TABLE "sticker_cache" ADD COLUMN "image_url" text NOT NULL DEFAULT '';
--> statement-breakpoint
ALTER TABLE "sticker_cache" DROP COLUMN "base64";
--> statement-breakpoint
ALTER TABLE "sticker_cache" DROP COLUMN "size";
@@ -43,6 +43,13 @@
"when": 1780657801437, "when": 1780657801437,
"tag": "0005_large_squadron_sinister", "tag": "0005_large_squadron_sinister",
"breakpoints": true "breakpoints": true
},
{
"idx": 6,
"version": "7",
"when": 1780900000000,
"tag": "0006_replace_base64_with_image_url",
"breakpoints": true
} }
] ]
} }
@@ -431,23 +431,23 @@ export const pgTextAnalysisCacheTable = pgTable(
/** /**
* Sticker Cache Table (PostgreSQL) * Sticker Cache Table (PostgreSQL)
* Stores base64-encoded sticker images for fast retrieval in media moderation. *
* Replaces the file-based .dat + index.json cache. * Stores uploaded sticker image URLs instead of raw base64 blobs.
* Stickers are uploaded to the external upload service once and the URL is
* cached here so subsequent occurrences reuse the same URL for vision analysis.
* *
* TTL: 7 days (enforced at query time via fetched_at) * TTL: 7 days (enforced at query time via fetched_at)
* Eviction: LRU by fetched_at, max 100MB total * Eviction: max 5000 entries (LRU by fetched_at)
*/ */
export const pgStickerCacheTable = pgTable( export const pgStickerCacheTable = pgTable(
"sticker_cache", "sticker_cache",
{ {
/** Sanitized sticker name (encodeURIComponent + %→_) — primary key. */ /** Sanitized sticker name (encodeURIComponent + %→_) — primary key. */
name: pgText("name").primaryKey(), name: pgText("name").primaryKey(),
/** Base64-encoded image data. */ /** Uploaded image URL (tele/picser). Used directly as image_url in vision API. */
base64: pgText("base64").notNull(), imageUrl: pgText("image_url").notNull().default(""),
/** MIME type of the image (e.g. "image/png", "image/gif"). */ /** MIME type of the image (e.g. "image/png", "image/gif"). */
mime_type: pgText("mime_type").notNull(), mime_type: pgText("mime_type").notNull(),
/** Byte length of the base64 string (for efficient SUM() eviction queries). */
size: pgInteger("size").notNull(),
/** Epoch millis when this entry was stored. Used for TTL and LRU eviction. */ /** Epoch millis when this entry was stored. Used for TTL and LRU eviction. */
fetched_at: pgBigint("fetched_at", { mode: "number" }).notNull(), fetched_at: pgBigint("fetched_at", { mode: "number" }).notNull(),
}, },