Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
Remove blob/tree/stats API cache
Merged rudolfs opened 1 year ago

This is now done properly in radicle-httpd via cache-control headers.

check check-visual check-unit-test check-httpd-api-unit-test check-e2e check-build 👉 Preview 👉 Workflow runs 👉 Branch on GitHub

3 files changed +0 -37 521ccd09 3bf25fe8
modified httpd-client/lib/project.ts
@@ -1,4 +1,3 @@
-
import { LRUCache } from "lru-cache";
import type { Commit, Commits } from "./project/commit.js";
import type { Embed } from "./project/comment.js";
import type { Fetcher, RequestOptions } from "./fetcher.js";
@@ -147,14 +146,6 @@ export type ProjectListQuery = {
export class Client {
  #fetcher: Fetcher;

-
  // We make the cache a static variable because clients are usually not
-
  // persisted and new instances are frequently created.
-
  static #cache = {
-
    tree: new LRUCache<string, Tree>({ max: 300 }),
-
    stats: new LRUCache<string, TreeStats>({ max: 300 }),
-
    blob: new LRUCache<string, Blob>({ max: 500 }),
-
  };
-

  public constructor(fetcher: Fetcher) {
    this.#fetcher = fetcher;
  }
@@ -234,11 +225,6 @@ export class Client {
    path: string,
    options?: RequestOptions,
  ): Promise<Blob> {
-
    const cacheKey = `blob:${sha}:${path}`;
-
    const cachedBlob = Client.#cache.blob.get(cacheKey);
-
    if (cachedBlob) {
-
      return cachedBlob;
-
    }
    const blob = await this.#fetcher.fetchOk(
      {
        method: "GET",
@@ -247,7 +233,6 @@ export class Client {
      },
      blobSchema,
    );
-
    Client.#cache.blob.set(cacheKey, blob);
    return blob;
  }

@@ -257,11 +242,6 @@ export class Client {
    path?: string,
    options?: RequestOptions,
  ): Promise<Tree> {
-
    const cacheKey = `tree:${sha}:${path}`;
-
    const cachedTree = Client.#cache.tree.get(cacheKey);
-
    if (cachedTree) {
-
      return cachedTree;
-
    }
    const tree = await this.#fetcher.fetchOk(
      {
        method: "GET",
@@ -270,7 +250,6 @@ export class Client {
      },
      treeSchema,
    );
-
    Client.#cache.tree.set(cacheKey, tree);
    return tree;
  }

@@ -279,11 +258,6 @@ export class Client {
    sha: string,
    options?: RequestOptions,
  ): Promise<TreeStats> {
-
    const cacheKey = `tree:stats:${sha}`;
-
    const cachedTree = Client.#cache.stats.get(cacheKey);
-
    if (cachedTree) {
-
      return cachedTree;
-
    }
    const tree = await this.#fetcher.fetchOk(
      {
        method: "GET",
@@ -292,7 +266,6 @@ export class Client {
      },
      treeStatsSchema,
    );
-
    Client.#cache.stats.set(cacheKey, tree);
    return tree;
  }

modified package-lock.json
@@ -20,7 +20,6 @@
        "hast-util-to-dom": "^4.0.0",
        "hast-util-to-html": "^9.0.0",
        "lodash": "^4.17.21",
-
        "lru-cache": "^10.2.0",
        "marked": "^12.0.1",
        "marked-katex-extension": "^5.0.1",
        "marked-linkify-it": "^3.1.9",
@@ -3316,14 +3315,6 @@
        "get-func-name": "^2.0.1"
      }
    },
-
    "node_modules/lru-cache": {
-
      "version": "10.2.0",
-
      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz",
-
      "integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==",
-
      "engines": {
-
        "node": "14 || >=16.14"
-
      }
-
    },
    "node_modules/magic-string": {
      "version": "0.30.8",
      "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.8.tgz",
modified package.json
@@ -58,7 +58,6 @@
    "hast-util-to-dom": "^4.0.0",
    "hast-util-to-html": "^9.0.0",
    "lodash": "^4.17.21",
-
    "lru-cache": "^10.2.0",
    "marked": "^12.0.1",
    "marked-katex-extension": "^5.0.1",
    "marked-linkify-it": "^3.1.9",