Skip to content

Commit f353ec4

Browse files
committed
fix: improve widgets build performance
1 parent ecaa050 commit f353ec4

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

apps/main/src/pages/widget/comment/[pageURL].tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { query } from '$/server/common/gql';
2626
import { ThemeOfPageDocument } from '$/server/graphql/generated/page';
2727
import {
2828
PageByUrlOnlyDocument,
29-
PagesDocument,
29+
FreshPagesDocument,
3030
} from '$/server/graphql/generated/page';
3131
import { CommonWidgetProps } from '$/types/page.type';
3232
import { Theme } from '$/types/theme.type';
@@ -87,10 +87,16 @@ const client = getAdminGqlClient();
8787

8888
// Get all project then prerender all their page comments
8989
export const getStaticPaths: GetStaticPaths<PathParams> = async () => {
90-
const pages = await query(PagesDocument, {}, 'pages');
90+
const freshPages = await query(
91+
FreshPagesDocument,
92+
{
93+
limit: 50,
94+
},
95+
'pages',
96+
);
9197

9298
const paths: { params: PathParams }[] =
93-
pages.map(({ url }) => {
99+
freshPages.map(({ url }) => {
94100
return {
95101
params: {
96102
pageURL: url,

apps/main/src/server/graphql/generated/page.tsx

+51-6
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ export type UpdatePagesMutation = {
4949
} | null;
5050
};
5151

52-
export type PagesQueryVariables = Types.Exact<{ [key: string]: never }>;
52+
export type FreshPagesQueryVariables = Types.Exact<{
53+
limit: Types.Scalars['Int'];
54+
}>;
5355

54-
export type PagesQuery = {
56+
export type FreshPagesQuery = {
5557
__typename?: 'query_root';
56-
pages: Array<{ __typename?: 'Page'; id: string; url: string }>;
58+
pages: Array<{
59+
__typename?: 'Page';
60+
id: string;
61+
url: string;
62+
createdAt: string;
63+
}>;
5764
};
5865

5966
export type PageByUrlOnlyQueryVariables = Types.Exact<{
@@ -447,32 +454,70 @@ export const UpdatePagesDocument = {
447454
},
448455
],
449456
} as unknown as DocumentNode<UpdatePagesMutation, UpdatePagesMutationVariables>;
450-
export const PagesDocument = {
457+
export const FreshPagesDocument = {
451458
kind: 'Document',
452459
definitions: [
453460
{
454461
kind: 'OperationDefinition',
455462
operation: 'query',
456-
name: { kind: 'Name', value: 'pages' },
463+
name: { kind: 'Name', value: 'freshPages' },
464+
variableDefinitions: [
465+
{
466+
kind: 'VariableDefinition',
467+
variable: {
468+
kind: 'Variable',
469+
name: { kind: 'Name', value: 'limit' },
470+
},
471+
type: {
472+
kind: 'NonNullType',
473+
type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } },
474+
},
475+
},
476+
],
457477
selectionSet: {
458478
kind: 'SelectionSet',
459479
selections: [
460480
{
461481
kind: 'Field',
462482
name: { kind: 'Name', value: 'pages' },
483+
arguments: [
484+
{
485+
kind: 'Argument',
486+
name: { kind: 'Name', value: 'order_by' },
487+
value: {
488+
kind: 'ObjectValue',
489+
fields: [
490+
{
491+
kind: 'ObjectField',
492+
name: { kind: 'Name', value: 'createdAt' },
493+
value: { kind: 'EnumValue', value: 'desc' },
494+
},
495+
],
496+
},
497+
},
498+
{
499+
kind: 'Argument',
500+
name: { kind: 'Name', value: 'limit' },
501+
value: {
502+
kind: 'Variable',
503+
name: { kind: 'Name', value: 'limit' },
504+
},
505+
},
506+
],
463507
selectionSet: {
464508
kind: 'SelectionSet',
465509
selections: [
466510
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
467511
{ kind: 'Field', name: { kind: 'Name', value: 'url' } },
512+
{ kind: 'Field', name: { kind: 'Name', value: 'createdAt' } },
468513
],
469514
},
470515
},
471516
],
472517
},
473518
},
474519
],
475-
} as unknown as DocumentNode<PagesQuery, PagesQueryVariables>;
520+
} as unknown as DocumentNode<FreshPagesQuery, FreshPagesQueryVariables>;
476521
export const PageByUrlOnlyDocument = {
477522
kind: 'Document',
478523
definitions: [

apps/main/src/server/graphql/page.graphql

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ mutation updatePages($projectId: uuid!, $title: String!, $url: String!) {
3737
}
3838
}
3939

40-
# Used in pages/widget/comment/[pageId].tsx
41-
query pages {
42-
pages {
40+
# Used in pages/widget/comment/[pageURL].tsx
41+
query freshPages($limit: Int!) {
42+
pages(order_by: { createdAt: desc }, limit: $limit) {
4343
id
4444
url
45+
createdAt
4546
}
4647
}
4748

0 commit comments

Comments
 (0)