mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
Remove caching projects found status
This commit is contained in:
@@ -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