mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-15 11:20:36 +08:00
Remove caching projects found status
This commit is contained in:
Generated
-9
@@ -19,7 +19,6 @@
|
||||
"hast-util-to-dom": "^4.0.0",
|
||||
"hast-util-to-html": "^9.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"lru-cache": "^10.1.0",
|
||||
"marked": "^11.1.1",
|
||||
"marked-katex-extension": "^5.0.0",
|
||||
"marked-linkify-it": "^3.1.8",
|
||||
@@ -3304,14 +3303,6 @@
|
||||
"get-func-name": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "10.1.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.1.0.tgz",
|
||||
"integrity": "sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==",
|
||||
"engines": {
|
||||
"node": "14 || >=16.14"
|
||||
}
|
||||
},
|
||||
"node_modules/magic-string": {
|
||||
"version": "0.30.5",
|
||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.5.tgz",
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
"hast-util-to-dom": "^4.0.0",
|
||||
"hast-util-to-html": "^9.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"lru-cache": "^10.1.0",
|
||||
"marked": "^11.1.1",
|
||||
"marked-katex-extension": "^5.0.0",
|
||||
"marked-linkify-it": "^3.1.8",
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { LRUCache } from "lru-cache";
|
||||
|
||||
export function cached<Args extends unknown[], V>(
|
||||
f: (...args: Args) => Promise<V>,
|
||||
makeKey: (...args: Args) => string,
|
||||
options?: LRUCache.Options<string, { value: V }, unknown>,
|
||||
): (...args: Args) => Promise<V> {
|
||||
const cache = new LRUCache(options || { max: 500 });
|
||||
return async function (...args: Args): Promise<V> {
|
||||
const key = makeKey(...args);
|
||||
const cached = cache.get(key);
|
||||
|
||||
if (cached === undefined) {
|
||||
const value = await f(...args);
|
||||
cache.set(key, { value });
|
||||
return value;
|
||||
} else {
|
||||
return cached.value;
|
||||
}
|
||||
};
|
||||
}
|
||||
+1
-9
@@ -2,7 +2,6 @@ import type { BaseUrl, Project } from "@httpd-client";
|
||||
|
||||
import { HttpdClient } from "@httpd-client";
|
||||
import { isFulfilled } from "@app/lib/utils";
|
||||
import { cached } from "./cache";
|
||||
import {
|
||||
fetchLastCommit,
|
||||
loadProjectActivity,
|
||||
@@ -61,14 +60,7 @@ export async function getProjectsListingData(projects: ProjectBaseUrl[]) {
|
||||
});
|
||||
}
|
||||
|
||||
export const cacheQueryProject = cached(
|
||||
queryProject,
|
||||
(baseUrl: BaseUrl, projectId: string) =>
|
||||
JSON.stringify({ baseUrl, projectId }),
|
||||
{ max: 200, ttl: 60 * 60 * 1000 },
|
||||
);
|
||||
|
||||
async function queryProject(
|
||||
export async function queryProject(
|
||||
baseUrl: BaseUrl,
|
||||
projectId: string,
|
||||
): Promise<"found" | "notFound"> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { ProjectRoute } from "@app/views/projects/router";
|
||||
|
||||
import { cacheQueryProject } from "@app/lib/projects";
|
||||
import { queryProject } from "@app/lib/projects";
|
||||
import { config } from "@app/lib/config";
|
||||
import { formatPublicExplorer } from "@app/lib/utils";
|
||||
import { routeToPath, urlToRoute } from "@app/lib/router";
|
||||
@@ -98,7 +98,7 @@
|
||||
</div>
|
||||
<ul class="seed-list">
|
||||
{#each seedRoutes as seed}
|
||||
{#await cacheQueryProject(seed.node, seed.project)}
|
||||
{#await queryProject(seed.node, seed.project)}
|
||||
<li class="seed-item">
|
||||
<span class="seed txt-bold">
|
||||
<IconSmall name="globe" />
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { ActiveTab } from "./Header.svelte";
|
||||
import type { BaseUrl, Project } from "@httpd-client";
|
||||
|
||||
import { cacheQueryProject } from "@app/lib/projects";
|
||||
import { queryProject } from "@app/lib/projects";
|
||||
import { httpdStore, api } from "@app/lib/httpd";
|
||||
import { isLocal } from "@app/lib/utils";
|
||||
import { onMount } from "svelte";
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
httpdStore.subscribe(async () => {
|
||||
if ($httpdStore.state !== "stopped" && !queryingLocalProject) {
|
||||
await cacheQueryProject(api.baseUrl, project.id);
|
||||
await detectLocalProject();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
|
||||
async function detectLocalProject(): Promise<void> {
|
||||
queryingLocalProject = true;
|
||||
localProject = await cacheQueryProject(api.baseUrl, project.id);
|
||||
localProject = await queryProject(api.baseUrl, project.id);
|
||||
queryingLocalProject = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user