Skip to content

Commit

Permalink
improve reset logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Feb 21, 2024
1 parent 39f828b commit f9bacdb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
39 changes: 32 additions & 7 deletions src/clickhouse/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function query_chains() {
.then((response) => response.json<Array<{ chain: string }>>())
.then((chains) => chains.map(({ chain }) => chain))
.catch(() => []);
logger.info('[store:query_chains]', `Total chains: ${chains.length} (${chains.join(", ")})`);
logger.info('[store::query_chains]', `Total chains: ${chains.length} (${chains.join(", ")})`);

return chains;
}
Expand All @@ -39,16 +39,41 @@ export async function query_module_hashes() {
.then((response) => response.json<Array<{ module_hash: string }>>())
.then((moduleHashes) => moduleHashes.map(({ module_hash }) => module_hash))
.catch(() => []);
logger.info('[store:query_module_hashes]', `Total module_hashes: ${module_hashes.length}`);
logger.info('[store::query_module_hashes]', `Total module_hashes: ${module_hashes.length}`);

return module_hashes;
}

export function reset() {
chains = null;
module_hashes = null;
tables = null;
logger.info('[reset]', "Cache has been cleared");
export async function reset(type: "chains"| "module_hashes" | "tables" | "databases" | "all" = "all") {
logger.info('[reset]', `cache reset for '${type}'`);
switch (type) {
case "chains":
chains = null;
await query_chains();
break;
case "module_hashes":
module_hashes = null;
await query_module_hashes();
break;
case "tables":
tables = null;
await show_tables();
break;
case "databases":
databases = null;
await show_databases();
break;
case "all":
chains = null;
module_hashes = null;
tables = null;
databases = null;
await query_chains();
await query_module_hashes();
await show_tables();
await show_databases();
break;
}
}

export async function show_tables() {
Expand Down
2 changes: 1 addition & 1 deletion src/fetch/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function handleSchemaRequest(req: Request, type: "sql" | "graphql")

try {
const executedSchemas = await executeCreateStatements(statements);
store.reset();
await store.reset("tables");
return toText(executedSchemas.join("\n"));
} catch (e) {
logger.error('[handleSchemaRequest]', e);
Expand Down

0 comments on commit f9bacdb

Please sign in to comment.