Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.2 KB
Raw Blame
import * as api from "@/lib/backend/api";

// Serialize ownership changes so a delayed release cannot undo a later retain.
let updates: Promise<void> = Promise.resolve();
const pendingReleases = new Set<string>();

function enqueue(update: () => Promise<void>): Promise<void> {
  const result = updates.then(update);
  updates = result.catch(() => {});
  return result;
}

async function flushReleases(): Promise<void> {
  while (pendingReleases.size) {
    const ids = [...pendingReleases].slice(0, 1024);
    await api.updateOracleRoutineOperationReferences([], ids);
    ids.forEach((id) => pendingReleases.delete(id));
  }
}

export function retainOracleRoutineOperations(ids: string[]): Promise<void> {
  return enqueue(async () => {
    ids.forEach((id) => pendingReleases.delete(id));
    // Failed cleanup is retried on normal lifecycle actions, never by a timer.
    await flushReleases().catch(() => {});
    if (ids.length) await api.updateOracleRoutineOperationReferences([...new Set(ids)], []);
  });
}

export function releaseOracleRoutineOperations(ids: string[]): Promise<void> {
  return enqueue(async () => {
    ids.forEach((id) => pendingReleases.add(id));
    await flushReleases();
  }).catch(() => {});
}