Skip to content

Commit

Permalink
Merge pull request #237 from tursodatabase/stop_waiting_for_schema_jobs
Browse files Browse the repository at this point in the history
Stop waiting for schema jobs
  • Loading branch information
haaawk authored Jul 8, 2024
2 parents ce2e148 + 0a81cc4 commit c795efa
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 278 deletions.
5 changes: 0 additions & 5 deletions packages/libsql-client/src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import "./helpers.js";

import type * as libsql from "../node.js";
import { createClient } from "../node.js";
import * as migrations from "../migrations";

jest.spyOn(migrations, "getIsSchemaDatabase").mockImplementation(
(_params) => new Promise((resolve) => resolve(false)),
);

const config = {
url: process.env.URL ?? "ws://localhost:8080",
Expand Down
15 changes: 0 additions & 15 deletions packages/libsql-client/src/__tests__/migrations.test.ts

This file was deleted.

34 changes: 0 additions & 34 deletions packages/libsql-client/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import {
import { SqlCache } from "./sql_cache.js";
import { encodeBaseUrl } from "@libsql/core/uri";
import { supportedUrlLink } from "@libsql/core/util";
import {
getIsSchemaDatabase,
waitForLastMigrationJobToFinish,
} from "./migrations.js";
import promiseLimit from "promise-limit";

export * from "@libsql/core/api";
Expand Down Expand Up @@ -76,9 +72,7 @@ const sqlCacheCapacity = 30;
export class HttpClient implements Client {
#client: hrana.HttpClient;
protocol: "http";
#url: URL;
#authToken: string | undefined;
#isSchemaDatabase: Promise<boolean> | undefined;
#promiseLimitFunction: ReturnType<typeof promiseLimit<any>>;

/** @private */
Expand All @@ -92,30 +86,17 @@ export class HttpClient implements Client {
this.#client = hrana.openHttp(url, authToken, customFetch);
this.#client.intMode = intMode;
this.protocol = "http";
this.#url = url;
this.#authToken = authToken;
this.#promiseLimitFunction = promiseLimit<any>(concurrency);
}

getIsSchemaDatabase(): Promise<boolean> {
if (this.#isSchemaDatabase === undefined) {
this.#isSchemaDatabase = getIsSchemaDatabase({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}

return this.#isSchemaDatabase;
}

private async limit<T>(fn: () => Promise<T>): Promise<T> {
return this.#promiseLimitFunction(fn);
}

async execute(stmt: InStatement): Promise<ResultSet> {
return this.limit<ResultSet>(async () => {
try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmt = stmtToHrana(stmt);

// Pipeline all operations, so `hrana.HttpClient` can open the stream, execute the statement and
Expand All @@ -129,13 +110,6 @@ export class HttpClient implements Client {
}

const rowsResult = await rowsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await waitForLastMigrationJobToFinish({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}

return resultSetFromHrana(rowsResult);
} catch (e) {
Expand All @@ -150,7 +124,6 @@ export class HttpClient implements Client {
): Promise<Array<ResultSet>> {
return this.limit<Array<ResultSet>>(async () => {
try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmts = stmts.map(stmtToHrana);
const version = await this.#client.getVersion();

Expand Down Expand Up @@ -180,13 +153,6 @@ export class HttpClient implements Client {
}

const results = await resultsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await waitForLastMigrationJobToFinish({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}

return results;
} catch (e) {
Expand Down
193 changes: 0 additions & 193 deletions packages/libsql-client/src/migrations.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/libsql-client/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import {
import { SqlCache } from "./sql_cache.js";
import { encodeBaseUrl } from "@libsql/core/uri";
import { supportedUrlLink } from "@libsql/core/util";
import {
getIsSchemaDatabase,
waitForLastMigrationJobToFinish,
} from "./migrations.js";
import promiseLimit from "promise-limit";

export * from "@libsql/core/api";
Expand Down Expand Up @@ -152,17 +148,6 @@ export class WsClient implements Client {
this.#promiseLimitFunction = promiseLimit<any>(concurrency);
}

getIsSchemaDatabase(): Promise<boolean> {
if (this.#isSchemaDatabase === undefined) {
this.#isSchemaDatabase = getIsSchemaDatabase({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}

return this.#isSchemaDatabase;
}

private async limit<T>(fn: () => Promise<T>): Promise<T> {
return this.#promiseLimitFunction(fn);
}
Expand All @@ -171,7 +156,6 @@ export class WsClient implements Client {
return this.limit<ResultSet>(async () => {
const streamState = await this.#openStream();
try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmt = stmtToHrana(stmt);

// Schedule all operations synchronously, so they will be pipelined and executed in a single
Expand All @@ -181,13 +165,6 @@ export class WsClient implements Client {
streamState.stream.closeGracefully();

const hranaRowsResult = await hranaRowsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await waitForLastMigrationJobToFinish({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}

return resultSetFromHrana(hranaRowsResult);
} catch (e) {
Expand All @@ -205,7 +182,6 @@ export class WsClient implements Client {
return this.limit<Array<ResultSet>>(async () => {
const streamState = await this.#openStream();
try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmts = stmts.map(stmtToHrana);
const version = await streamState.conn.client.getVersion();

Expand All @@ -221,13 +197,6 @@ export class WsClient implements Client {
);

const results = await resultsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await waitForLastMigrationJobToFinish({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}

return results;
} catch (e) {
Expand Down

0 comments on commit c795efa

Please sign in to comment.