feat: replace Redis with DragonflyDB
- Replace Redis server with DragonflyDB v1.40.1 (Redis protocol compatible) - Stop redis-server service, enable dragonfly service on 127.0.0.1:6379 - Configure dragonfly in /etc/dragonfly/dragonfly.conf (bind 127.0.0.1, maxmemory 2gb) - Update .env: remove REDIS_URL reference Improve database reliability: - Fix catalog-tree.ts: remove CAST(page_id AS CHAR) to enable index usage (122 rows vs 78k full scan) - Fix catalog-repair.ts: replace sql.raw() string interpolation with parameterized sql queries using quoteIdentifier() - Improve redis retry resilience: change retryStrategy to not give up after 3 attempts, enabling automatic reconnect after server restart Update documentation: - Update README: replace Redis references with DragonflyDB, add DragonflyDB setup section, update performance features list, update architecture diagram - biome and typecheck pass clean
This commit is contained in:
1 parent
9463c8d4da
commit
65e3915a5f
4 files changed
+89
-28
No files matched your search
@@ -12,7 +12,9 @@ function toInt(value: unknown, fallback = 0): number {
|
||||
|
||||
/**
|
||||
* Count catalog_items per page via raw SQL.
|
||||
* Real Habbo DBs often store page_id as VARCHAR; numeric groupBy fails or returns 0.
|
||||
* Real Habbo DBs often store page_id as VARCHAR. String literals match both
|
||||
* INT and VARCHAR columns while keeping the page_id index usable (CAST(... AS CHAR)
|
||||
* would force a full index scan).
|
||||
*/
|
||||
export async function getCatalogItemCounts(
|
||||
pageIds?: number[],
|
||||
@@ -26,7 +28,7 @@ export async function getCatalogItemCounts(
|
||||
const [rows] = (await db.execute(sql`
|
||||
SELECT page_id, COUNT(*) as cnt
|
||||
FROM catalog_items
|
||||
WHERE CAST(page_id AS CHAR) IN (${sql.join(idStrs, sql`, `)})
|
||||
WHERE page_id IN (${sql.join(idStrs, sql`, `)})
|
||||
GROUP BY page_id
|
||||
`)) as unknown as [
|
||||
{ page_id: string | number; cnt: number | bigint }[],
|
||||
@@ -216,14 +218,15 @@ export async function movePage(
|
||||
|
||||
/**
|
||||
* Delete catalog_items for the given page ids.
|
||||
* Habbo DBs often store page_id as VARCHAR; typed Int deletes can miss rows.
|
||||
* Habbo DBs often store page_id as VARCHAR; text delete on INT or VARCHAR
|
||||
* columns keeps the page_id index usable (CAST would force a full scan).
|
||||
*/
|
||||
async function deleteCatalogItemsByPageIds(pageIds: number[]): Promise<void> {
|
||||
if (pageIds.length === 0) return;
|
||||
const idStrs = pageIds.map(String);
|
||||
await db.execute(sql`
|
||||
DELETE FROM catalog_items
|
||||
WHERE CAST(page_id AS CHAR) IN (${sql.join(idStrs, sql`, `)})
|
||||
WHERE page_id IN (${sql.join(idStrs, sql`, `)})
|
||||
`);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user