perf(redis): reduce fetch-all rendering overhead
This commit is contained in:
1 parent
a81d6da604
commit
2fa4ffd074
5 files changed
+117
-35
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import type { RedisKeyInfo } from "@/lib/backend/api";
|
||||
|
||||
export function collectUniqueRedisKeys(keys: RedisKeyInfo[], loadedKeyRaws: Set<string>): RedisKeyInfo[] {
|
||||
const uniqueKeys: RedisKeyInfo[] = [];
|
||||
|
||||
for (const key of keys) {
|
||||
if (loadedKeyRaws.has(key.key_raw)) continue;
|
||||
loadedKeyRaws.add(key.key_raw);
|
||||
uniqueKeys.push(key);
|
||||
}
|
||||
|
||||
return uniqueKeys;
|
||||
}
|
||||
@@ -25,6 +25,7 @@ export interface RedisKeyTreeGroupNode {
|
||||
export type RedisKeyTreeNode = RedisKeyTreeLeafNode | RedisKeyTreeGroupNode;
|
||||
|
||||
export interface RedisKeyTreeRow {
|
||||
id: string;
|
||||
node: RedisKeyTreeNode;
|
||||
depth: number;
|
||||
}
|
||||
@@ -44,10 +45,12 @@ function buildLeafId(db: number, keyRaw: string): string {
|
||||
}
|
||||
|
||||
export function redisKeyToFlatTreeRow(key: RedisKeyInfo, db: number): RedisKeyTreeRow {
|
||||
const nodeId = buildLeafId(db, key.key_raw);
|
||||
return {
|
||||
id: nodeId,
|
||||
node: {
|
||||
kind: "leaf",
|
||||
id: buildLeafId(db, key.key_raw),
|
||||
id: nodeId,
|
||||
label: key.key_display,
|
||||
fullKeyDisplay: key.key_display,
|
||||
keyRaw: key.key_raw,
|
||||
@@ -220,7 +223,7 @@ export function flattenVisibleRedisKeyTree(nodes: RedisKeyTreeNode[], expandedGr
|
||||
const stack: RedisKeyTreeRow[] = [];
|
||||
|
||||
for (let index = nodes.length - 1; index >= 0; index--) {
|
||||
stack.push({ node: nodes[index], depth });
|
||||
stack.push({ id: nodes[index].id, node: nodes[index], depth });
|
||||
}
|
||||
|
||||
while (stack.length > 0) {
|
||||
@@ -231,7 +234,8 @@ export function flattenVisibleRedisKeyTree(nodes: RedisKeyTreeNode[], expandedGr
|
||||
|
||||
const childDepth = row.depth + 1;
|
||||
for (let index = row.node.children.length - 1; index >= 0; index--) {
|
||||
stack.push({ node: row.node.children[index], depth: childDepth });
|
||||
const child = row.node.children[index];
|
||||
stack.push({ id: child.id, node: child, depth: childDepth });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user