mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-04 22:31:33 +09:00
## Summary Remove avoidable latency from Builder resource loading and make Assets resources use the content database efficiently. ## Why Builder currently applies a one-second debounce to every uncached resource request. Assets queries also perform server-side preparation work that should be reused or deferred, making pagination and route changes noticeably slower than expected. ## Implementation plan - [x] Dispatch the complete set of currently computable page resources without the one-second debounce. - [x] Preserve batching, deduplication, exact-request caching, invalidation, and bounded queue draining. - [x] Add regression tests for immediate dispatch, batching, deduplication, invalidation, and queue draining. - [x] Cache compiled Assets content databases by the relevant project/build and asset revision. - [x] Run pagination, filtering, sorting, and metadata selection against the cached database without rebuilding it for each request. - [x] Fetch only referenced document content that is required by the query and keep graph reads parallel. - [x] Avoid generating and returning full diagnostics artifacts for ordinary canvas resource loads; load detailed diagnostics on demand. - [x] Preserve distinct loading and confirmed-empty states for article and author resources. - [x] Add coverage for paginated overview and article navigation behavior. - [x] Deep-review the complete change and remove redundant plan construction, duplicated JSON comparison, path-based diagnostics inference, and synthetic canvas diagnostics. - [x] Make resource and diagnostics invalidation race-safe, including invalidation during in-flight requests. - [x] Run formatting, tests, lint, type checking, package-boundary checks, and affected fixtures. ## Verification - `pnpm oxfmt --check` - `pnpm lint` - `pnpm check:package-boundaries` - `pnpm --filter @webstudio-is/content-engine test` (262 tests) - `pnpm --filter @webstudio-is/asset-uploader test` (184 tests) - `pnpm --filter @webstudio-is/builder test` (2,483 tests) - Typechecks for Content Engine, Project Build, Asset Uploader, and Builder - `pnpm fixtures` (passed; no fixture diff) The new invalidation regression tests were verified to fail against the previous behavior and pass with the fix. Agent evaluations were not run because they require separate approval. ## Known limitations None identified.
161 lines
4.0 KiB
TypeScript
161 lines
4.0 KiB
TypeScript
import type { AUTH_PROVIDERS } from "~/shared/session";
|
|
import { getAssetUploadApiUrl } from "@webstudio-is/sdk/runtime";
|
|
import { getAuthorizationServerOrigin } from "./origins";
|
|
import type { BuilderMode } from "../nano-states/misc";
|
|
|
|
const searchParams = (params: Record<string, string | undefined | null>) => {
|
|
const searchParams = new URLSearchParams();
|
|
for (const [key, value] of Object.entries(params)) {
|
|
if (typeof value === "string") {
|
|
searchParams.set(key, value);
|
|
}
|
|
}
|
|
const asString = searchParams.toString();
|
|
return asString === "" ? "" : `?${asString}`;
|
|
};
|
|
|
|
export type BuilderLinkParams = {
|
|
pageId?: string;
|
|
instanceSelector?: readonly string[];
|
|
authToken?: string;
|
|
pageHash?: string;
|
|
mode?: BuilderMode;
|
|
safemode?: boolean;
|
|
};
|
|
|
|
export const builderPath = ({
|
|
pageId,
|
|
instanceSelector,
|
|
authToken,
|
|
pageHash,
|
|
mode,
|
|
safemode = false,
|
|
}: BuilderLinkParams = {}) => {
|
|
return `/${searchParams({
|
|
pageId,
|
|
instance: instanceSelector?.join(","),
|
|
authToken,
|
|
pageHash,
|
|
mode,
|
|
safemode: safemode ? "true" : undefined,
|
|
})}`;
|
|
};
|
|
|
|
export const builderUrl = ({
|
|
projectId,
|
|
origin,
|
|
...link
|
|
}: BuilderLinkParams & {
|
|
projectId: string;
|
|
origin: string;
|
|
}) => {
|
|
const authServerOrigin = getAuthorizationServerOrigin(origin);
|
|
|
|
const url = new URL(builderPath(link), authServerOrigin);
|
|
|
|
const fragments = url.host.split(".");
|
|
if (fragments.length <= 3) {
|
|
fragments.splice(0, 0, "p-" + projectId);
|
|
} else {
|
|
// staging | development branches
|
|
fragments[0] = "p-" + projectId + "-dot-" + fragments[0];
|
|
}
|
|
|
|
url.host = fragments.join(".");
|
|
|
|
return url.href;
|
|
};
|
|
|
|
export const dashboardPath = (
|
|
view: "templates" | "search" | "projects" = "projects"
|
|
) => {
|
|
if (view === "projects") {
|
|
return `/dashboard`;
|
|
}
|
|
return `/dashboard/${view}`;
|
|
};
|
|
|
|
export const dashboardUrl = (props: { origin: string }) => {
|
|
const authServerOrigin = getAuthorizationServerOrigin(props.origin);
|
|
|
|
return `${authServerOrigin}/dashboard`;
|
|
};
|
|
|
|
export const cloneProjectUrl = (props: {
|
|
origin: string;
|
|
sourceAuthToken: string;
|
|
}) => {
|
|
const authServerOrigin = getAuthorizationServerOrigin(props.origin);
|
|
|
|
const searchParams = new URLSearchParams();
|
|
searchParams.set("projectToCloneAuthToken", props.sourceAuthToken);
|
|
|
|
return `${authServerOrigin}/dashboard?${searchParams.toString()}`;
|
|
};
|
|
|
|
export const loginPath = (params: {
|
|
error?: (typeof AUTH_PROVIDERS)[keyof typeof AUTH_PROVIDERS];
|
|
message?: string;
|
|
returnTo?: string;
|
|
}) => `/login${searchParams(params)}`;
|
|
|
|
export const logoutPath = () => "/logout";
|
|
export const restLogoutPath = () => "/dashboard-logout";
|
|
|
|
export const planSubscriptionPath = (subscriptionId?: string) => {
|
|
const urlSearchParams = new URLSearchParams();
|
|
urlSearchParams.set("return_url", window.location.href);
|
|
if (subscriptionId) {
|
|
urlSearchParams.set("subscription", subscriptionId);
|
|
}
|
|
|
|
return `/builder-payments/billing-portal/sessions?${urlSearchParams.toString()}`;
|
|
};
|
|
|
|
export const authCallbackPath = ({
|
|
provider,
|
|
}: {
|
|
provider: "google" | "github";
|
|
}) => `/auth/${provider}/callback`;
|
|
|
|
export const authPath = ({
|
|
provider,
|
|
}: {
|
|
provider: "google" | "github" | "dev";
|
|
}) => `/auth/${provider}`;
|
|
|
|
export const restAssetsUploadPath = ({
|
|
name,
|
|
width,
|
|
height,
|
|
}: {
|
|
name: string;
|
|
width?: number | undefined;
|
|
height?: number | undefined;
|
|
}) => {
|
|
const urlSearchParams = new URLSearchParams();
|
|
if (width !== undefined) {
|
|
urlSearchParams.set("width", String(width));
|
|
}
|
|
if (height !== undefined) {
|
|
urlSearchParams.set("height", String(height));
|
|
}
|
|
|
|
const query = urlSearchParams.toString();
|
|
if (query !== "") {
|
|
return `${getAssetUploadApiUrl(name)}?${query}`;
|
|
}
|
|
|
|
return getAssetUploadApiUrl(name);
|
|
};
|
|
|
|
export const getCanvasUrl = () => {
|
|
return `/canvas`;
|
|
};
|
|
|
|
export const restResourcesLoader = ({ diagnostics = false } = {}) =>
|
|
`/rest/resources-loader${diagnostics ? "?diagnostics=true" : ""}`;
|
|
|
|
export const marketplacePath = (method: string) =>
|
|
`/builder/marketplace/${method}`;
|