Skip to content

Commit

Permalink
feat: parallelize server-side queries in project page render (#1083)
Browse files Browse the repository at this point in the history
* Previously we'd await on each GraphQL query in sequence, which led to
  a slow render.
* This tries to parallelize what we can so that project pages can load
  faster
  • Loading branch information
ryscheng authored Mar 19, 2024
1 parent 9999dfa commit 85f190f
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions apps/frontend/app/project/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,44 @@ export default async function ProjectPage(props: ProjectPageProps) {
notFound();
}
const project = projectArray[0];
const projectId = project.project_id;
//console.log("project", project);

const { event_types: eventTypes } = await cachedGetAllEventTypes();
const { code_metrics_by_project: codeMetrics } =
await cachedGetCodeMetricsByProjectIds({
project_ids: [project.project_id],
});
const { onchain_metrics_by_project: onchainMetrics } =
await cachedGetOnchainMetricsByProjectIds({
project_ids: [project.project_id],
});
const { artifacts_by_project: artifactIds } =
await cachedGetArtifactIdsByProjectIds({
project_ids: [project.project_id],
});
const { projects_by_collection: collectionIds } =
await cachedGetCollectionIdsByProjectIds({
project_ids: [project.project_id],
});
const { artifacts } = await cachedGetArtifactsByIds({
artifact_ids: artifactIds.map((x: any) => x.artifact_id),
});
const { collections } = await cachedGetCollectionsByIds({
collection_ids: collectionIds.map((x: any) => x.collection_id),
});
// Parallelize getting things related to the project
const p1 = await Promise.all([
cachedGetAllEventTypes(),
cachedGetCodeMetricsByProjectIds({
project_ids: [projectId],
}),
cachedGetOnchainMetricsByProjectIds({
project_ids: [projectId],
}),
cachedGetArtifactIdsByProjectIds({
project_ids: [projectId],
}),
cachedGetCollectionIdsByProjectIds({
project_ids: [projectId],
}),
]);
const { event_types: eventTypes } = p1[0];
const { code_metrics_by_project: codeMetrics } = p1[1];
const { onchain_metrics_by_project: onchainMetrics } = p1[2];
const { artifacts_by_project: artifactIds } = p1[3];
const { projects_by_collection: collectionIds } = p1[4];

// Parallelize getting artifacts and collections
const p2 = await Promise.all([
cachedGetArtifactsByIds({
artifact_ids: artifactIds.map((x: any) => x.artifact_id),
}),
cachedGetCollectionsByIds({
collection_ids: collectionIds.map((x: any) => x.collection_id),
}),
]);
const { artifacts } = p2[0];
const { collections } = p2[1];

// Get Plasmic component
const plasmicData = await cachedFetchComponent(PLASMIC_COMPONENT);
const compMeta = plasmicData.entryCompMetas[0];

Expand Down

0 comments on commit 85f190f

Please sign in to comment.