Skip to content

Commit 0fae6fd

Browse files
improve: Template, package and skill reads no longer wait 0.4s per uncached query (#4798)
* perf(schema): expose validation-free helpers on their own entry points * perf(http): serve unscoped and API-token Template reads from the narrow path * perf(convex): keep the schema validation library out of read modules * docs(specs): record the Template read path and module startup boundary * chore(convex): regenerate API types for the new lib modules * fix(http): tie reserved endpoint words to the router and narrow the spec claim * fix(cli): ship the Template manifest summary module with the packed schemas
1 parent 475ce61 commit 0fae6fd

59 files changed

Lines changed: 831 additions & 549 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎bun.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎convex/_generated/api.d.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ import type * as lib_publicBrowse from "../lib/publicBrowse.js";
188188
import type * as lib_publicPluginArtwork from "../lib/publicPluginArtwork.js";
189189
import type * as lib_publicRouteReservations from "../lib/publicRouteReservations.js";
190190
import type * as lib_publishAttemptOperationalRecovery from "../lib/publishAttemptOperationalRecovery.js";
191+
import type * as lib_publishAttemptState from "../lib/publishAttemptState.js";
191192
import type * as lib_publishLimits from "../lib/publishLimits.js";
192193
import type * as lib_publishStorage from "../lib/publishStorage.js";
193194
import type * as lib_publisherAbuseBenchmark from "../lib/publisherAbuseBenchmark.js";
@@ -258,6 +259,7 @@ import type * as lib_skills_fileHash from "../lib/skills/fileHash.js";
258259
import type * as lib_skills_frontmatterValue from "../lib/skills/frontmatterValue.js";
259260
import type * as lib_skills_index from "../lib/skills/index.js";
260261
import type * as lib_skills_publicVersions from "../lib/skills/publicVersions.js";
262+
import type * as lib_skills_skillMarkdown from "../lib/skills/skillMarkdown.js";
261263
import type * as lib_skills_slugResolution from "../lib/skills/slugResolution.js";
262264
import type * as lib_skillsShCatalogEnvironment from "../lib/skillsShCatalogEnvironment.js";
263265
import type * as lib_skillsShCatalogFixtures from "../lib/skillsShCatalogFixtures.js";
@@ -548,6 +550,7 @@ declare const fullApi: ApiFromModules<{
548550
"lib/publicPluginArtwork": typeof lib_publicPluginArtwork;
549551
"lib/publicRouteReservations": typeof lib_publicRouteReservations;
550552
"lib/publishAttemptOperationalRecovery": typeof lib_publishAttemptOperationalRecovery;
553+
"lib/publishAttemptState": typeof lib_publishAttemptState;
551554
"lib/publishLimits": typeof lib_publishLimits;
552555
"lib/publishStorage": typeof lib_publishStorage;
553556
"lib/publisherAbuseBenchmark": typeof lib_publisherAbuseBenchmark;
@@ -618,6 +621,7 @@ declare const fullApi: ApiFromModules<{
618621
"lib/skills/frontmatterValue": typeof lib_skills_frontmatterValue;
619622
"lib/skills/index": typeof lib_skills_index;
620623
"lib/skills/publicVersions": typeof lib_skills_publicVersions;
624+
"lib/skills/skillMarkdown": typeof lib_skills_skillMarkdown;
621625
"lib/skills/slugResolution": typeof lib_skills_slugResolution;
622626
"lib/skillsShCatalogEnvironment": typeof lib_skillsShCatalogEnvironment;
623627
"lib/skillsShCatalogFixtures": typeof lib_skillsShCatalogFixtures;

‎convex/catalogFeed.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import type {
2+
CatalogFeedPluginEntry,
3+
CatalogFeedSkillEntry,
4+
ExperimentalTemplateFeedEntry,
5+
} from "clawhub-schema";
16
import {
27
CATALOG_FEED_GITHUB_SOURCE_REF,
38
CATALOG_FEED_ID,
@@ -12,9 +17,6 @@ import {
1217
serializeCatalogFeed,
1318
serializeExperimentalTemplateFeed,
1419
parseExperimentalTemplateFeed,
15-
type CatalogFeedPluginEntry,
16-
type CatalogFeedSkillEntry,
17-
type ExperimentalTemplateFeedEntry,
1820
} from "clawhub-schema";
1921
import { v } from "convex/values";
2022
import { internal } from "./_generated/api";

‎convex/devSeed.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
normalizeCatalogTopics,
66
normalizePluginCategories,
77
resolvePluginCategories,
8-
} from "clawhub-schema";
8+
} from "clawhub-schema/catalogMetadata";
99
import { type Infer, type ObjectType, v } from "convex/values";
1010
import { internal } from "./_generated/api";
1111
import type { Doc, Id } from "./_generated/dataModel";

‎convex/featuredArtifacts.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPluginDiscoveryExclusion } from "clawhub-schema";
1+
import { getPluginDiscoveryExclusion } from "clawhub-schema/pluginCategories";
22
import { v } from "convex/values";
33
import type { QueryCtx } from "./_generated/server";
44
import { internalQuery } from "./functions";

‎convex/httpApiV1/contentRightsV1.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiRoutes } from "clawhub-schema";
1+
import { ApiRoutes } from "clawhub-schema/routes";
22
import type { ActionCtx } from "../_generated/server";
33
import { applyRateLimit } from "../lib/httpRateLimit";
44
import {

‎convex/httpApiV1/packagesV1.ts‎

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import type {
2+
ApiV1PackageCategoriesBatchRequest,
3+
ApiV1PackageSecurityResponse,
4+
ApiV1PluginOverviewResponse,
5+
PackageListItem,
6+
PackagePublishMetadata,
7+
PackageAppealListStatus,
8+
PackageModerationQueueStatus,
9+
PackageOfficialMigrationListPhase,
10+
PackageReportListStatus,
11+
PluginCategorySlug,
12+
ServerPackagePublishRequest,
13+
} from "clawhub-schema";
114
import {
2-
ApiRoutes,
315
ApiV1PackageScanBatchRequestSchema,
416
ApiV1PackageScanBatchStatusRequestSchema,
517
ApiV1PackageCategoriesBatchRequestSchema,
@@ -15,7 +27,6 @@ import {
1527
PackageAppealResolveRequestSchema,
1628
PackageAppealRequestSchema,
1729
PackageOfficialMigrationUpsertRequestSchema,
18-
PACKAGE_CATEGORY_BATCH_LIMIT,
1930
PackageRepairNameRequestSchema,
2031
PackageRepairRuntimeIdRequestSchema,
2132
PackageReportRequestSchema,
@@ -25,24 +36,13 @@ import {
2536
PackageTransferRequestSchema,
2637
PackageTrustedPublisherUpsertRequestSchema,
2738
PublishTokenMintRequestSchema,
28-
formatSecurityAuditOverview,
29-
aggregateAuditVerdict,
30-
normalizeContentType,
31-
isTemplateCategorySlug,
32-
isPluginCategorySlug,
3339
parseArk,
34-
type ApiV1PackageCategoriesBatchRequest,
35-
type ApiV1PackageSecurityResponse,
36-
type ApiV1PluginOverviewResponse,
37-
type PackageListItem,
38-
type PackagePublishMetadata,
39-
type PackageAppealListStatus,
40-
type PackageModerationQueueStatus,
41-
type PackageOfficialMigrationListPhase,
42-
type PackageReportListStatus,
43-
type PluginCategorySlug,
44-
type ServerPackagePublishRequest,
4540
} from "clawhub-schema";
41+
import { isTemplateCategorySlug, isPluginCategorySlug } from "clawhub-schema/catalogMetadata";
42+
import { PACKAGE_CATEGORY_BATCH_LIMIT } from "clawhub-schema/packageLimits";
43+
import { ApiRoutes } from "clawhub-schema/routes";
44+
import { formatSecurityAuditOverview, aggregateAuditVerdict } from "clawhub-schema/securityAudit";
45+
import { normalizeContentType } from "clawhub-schema/textFiles";
4646
import { api, internal } from "../_generated/api";
4747
import type { Doc, Id } from "../_generated/dataModel";
4848
import type { ActionCtx } from "../_generated/server";
@@ -51,8 +51,9 @@ import { getOptionalActiveAuthUserIdFromAction } from "../lib/access";
5151
import { getOptionalApiTokenUserId, requireApiTokenUser } from "../lib/apiTokenAuth";
5252
import {
5353
PLUGIN_CATALOG_CURSOR_PREFIX,
54-
compareCatalogItems,
54+
type CatalogSearchEntry,
5555
compareCatalogItemsForSort,
56+
compareCatalogSearchEntries,
5657
encodePluginCatalogCursor,
5758
ensureCatalogSourcePage,
5859
finalizeCatalogSource,
@@ -115,7 +116,6 @@ import {
115116
MAX_CLAWPACK_BYTES,
116117
MAX_PUBLISH_FILE_BYTES,
117118
} from "../lib/publishLimits";
118-
import { isCuratedSearchResult } from "../lib/searchRanking";
119119
import {
120120
getPublicSkillVersionAccessBlock,
121121
getPublicSkillVersionDownloadBlock,
@@ -697,12 +697,6 @@ type PluginOverviewItem = CatalogListItem & {
697697
trendingRank?: number;
698698
};
699699

700-
type CatalogSearchEntry = {
701-
score: number;
702-
rankTier?: number;
703-
package: CatalogListItem;
704-
};
705-
706700
const UNIFIED_CATALOG_CURSOR_PREFIX = "pkgcatalog:";
707701
const LEGACY_PLUGIN_SEARCH_CURSOR_PREFIX = "pkgpluginsearch:";
708702
const SKILL_CATALOG_CURSOR_PREFIX = "skillcat:";
@@ -858,27 +852,6 @@ function normalizePublicPackageSort(sort: (typeof PACKAGE_LIST_SORT_VALUES)[numb
858852
return sort === "installs" ? "downloads" : sort;
859853
}
860854

861-
export function compareCatalogSearchEntries(a: CatalogSearchEntry, b: CatalogSearchEntry) {
862-
return (
863-
Number(
864-
isCuratedSearchResult({
865-
isOfficial: b.package.isOfficial,
866-
featured: typeof b.package.featuredAt === "number",
867-
}),
868-
) -
869-
Number(
870-
isCuratedSearchResult({
871-
isOfficial: a.package.isOfficial,
872-
featured: typeof a.package.featuredAt === "number",
873-
}),
874-
) ||
875-
(a.rankTier ?? Number.POSITIVE_INFINITY) - (b.rankTier ?? Number.POSITIVE_INFINITY) ||
876-
b.score - a.score ||
877-
Number(b.package.isOfficial) - Number(a.package.isOfficial) ||
878-
compareCatalogItems(a.package, b.package)
879-
);
880-
}
881-
882855
function toPublicCatalogSearchEntry(entry: CatalogSearchEntry) {
883856
return {
884857
score: entry.score,

‎convex/httpApiV1/shared.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
export { contentDispositionAttachment } from "../lib/contentDisposition";
2-
import {
3-
CliPublishRequestSchema,
4-
decodeUtf8Text,
5-
getClawHubRuntimeEnvironment,
6-
normalizeContentType,
7-
parseArk,
8-
type ArkValidator,
9-
} from "clawhub-schema";
2+
import type { ArkValidator } from "clawhub-schema";
3+
import { CliPublishRequestSchema, parseArk } from "clawhub-schema";
4+
import { getClawHubRuntimeEnvironment } from "clawhub-schema/rolloutCapabilities";
5+
import { decodeUtf8Text, normalizeContentType } from "clawhub-schema/textFiles";
106
import { internal } from "../_generated/api";
117
import type { Doc, Id } from "../_generated/dataModel";
128
import type { ActionCtx } from "../_generated/server";

‎convex/httpApiV1/skillsV1.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import type { SkillAppealListStatus, SkillReportListStatus } from "clawhub-schema";
12
import {
2-
ApiRoutes,
33
ApiV1SkillUploadUrlRequestSchema,
44
ApiV1SkillBulkRescanBatchRequestSchema,
55
ApiV1SkillBulkRescanStatusRequestSchema,
@@ -12,12 +12,11 @@ import {
1212
SkillAppealResolveRequestSchema,
1313
SkillReportTriageRequestSchema,
1414
SkillVersionRevokeRequestSchema,
15-
formatSecurityAuditOverview,
16-
normalizeContentType,
1715
parseArk,
18-
type SkillAppealListStatus,
19-
type SkillReportListStatus,
2016
} from "clawhub-schema";
17+
import { ApiRoutes } from "clawhub-schema/routes";
18+
import { formatSecurityAuditOverview } from "clawhub-schema/securityAudit";
19+
import { normalizeContentType } from "clawhub-schema/textFiles";
2120
import { api, internal } from "../_generated/api";
2221
import type { Doc, Id } from "../_generated/dataModel";
2322
import type { ActionCtx } from "../_generated/server";

‎convex/lib/catalogPage.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PackageListItem } from "clawhub-schema";
22
import { compareRecommendationStats } from "./recommendationScore";
3+
import { isCuratedSearchResult } from "./searchRanking";
34

45
type CatalogListItem = PackageListItem & { ownerOfficial?: boolean };
56
type CatalogSort = "recommended" | "updated" | "downloads" | "installs" | "trending";
@@ -142,3 +143,30 @@ export function compareCatalogItemsForSort(
142143
}
143144
return compareCatalogItems(a, b);
144145
}
146+
147+
export type CatalogSearchEntry = {
148+
score: number;
149+
rankTier?: number;
150+
package: CatalogListItem;
151+
};
152+
153+
export function compareCatalogSearchEntries(a: CatalogSearchEntry, b: CatalogSearchEntry) {
154+
return (
155+
Number(
156+
isCuratedSearchResult({
157+
isOfficial: b.package.isOfficial,
158+
featured: typeof b.package.featuredAt === "number",
159+
}),
160+
) -
161+
Number(
162+
isCuratedSearchResult({
163+
isOfficial: a.package.isOfficial,
164+
featured: typeof a.package.featuredAt === "number",
165+
}),
166+
) ||
167+
(a.rankTier ?? Number.POSITIVE_INFINITY) - (b.rankTier ?? Number.POSITIVE_INFINITY) ||
168+
b.score - a.score ||
169+
Number(b.package.isOfficial) - Number(a.package.isOfficial) ||
170+
compareCatalogItems(a.package, b.package)
171+
);
172+
}

0 commit comments

Comments
 (0)