Skip to content

Commit

Permalink
fix: improve widgets build performance
Browse files Browse the repository at this point in the history
  • Loading branch information
devrsi0n committed Sep 17, 2022
1 parent ecaa050 commit f353ec4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
12 changes: 9 additions & 3 deletions apps/main/src/pages/widget/comment/[pageURL].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { query } from '$/server/common/gql';
import { ThemeOfPageDocument } from '$/server/graphql/generated/page';
import {
PageByUrlOnlyDocument,
PagesDocument,
FreshPagesDocument,
} from '$/server/graphql/generated/page';
import { CommonWidgetProps } from '$/types/page.type';
import { Theme } from '$/types/theme.type';
Expand Down Expand Up @@ -87,10 +87,16 @@ const client = getAdminGqlClient();

// Get all project then prerender all their page comments
export const getStaticPaths: GetStaticPaths<PathParams> = async () => {
const pages = await query(PagesDocument, {}, 'pages');
const freshPages = await query(
FreshPagesDocument,
{
limit: 50,
},
'pages',
);

const paths: { params: PathParams }[] =
pages.map(({ url }) => {
freshPages.map(({ url }) => {
return {
params: {
pageURL: url,
Expand Down
57 changes: 51 additions & 6 deletions apps/main/src/server/graphql/generated/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ export type UpdatePagesMutation = {
} | null;
};

export type PagesQueryVariables = Types.Exact<{ [key: string]: never }>;
export type FreshPagesQueryVariables = Types.Exact<{
limit: Types.Scalars['Int'];
}>;

export type PagesQuery = {
export type FreshPagesQuery = {
__typename?: 'query_root';
pages: Array<{ __typename?: 'Page'; id: string; url: string }>;
pages: Array<{
__typename?: 'Page';
id: string;
url: string;
createdAt: string;
}>;
};

export type PageByUrlOnlyQueryVariables = Types.Exact<{
Expand Down Expand Up @@ -447,32 +454,70 @@ export const UpdatePagesDocument = {
},
],
} as unknown as DocumentNode<UpdatePagesMutation, UpdatePagesMutationVariables>;
export const PagesDocument = {
export const FreshPagesDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: { kind: 'Name', value: 'pages' },
name: { kind: 'Name', value: 'freshPages' },
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {
kind: 'Variable',
name: { kind: 'Name', value: 'limit' },
},
type: {
kind: 'NonNullType',
type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } },
},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'pages' },
arguments: [
{
kind: 'Argument',
name: { kind: 'Name', value: 'order_by' },
value: {
kind: 'ObjectValue',
fields: [
{
kind: 'ObjectField',
name: { kind: 'Name', value: 'createdAt' },
value: { kind: 'EnumValue', value: 'desc' },
},
],
},
},
{
kind: 'Argument',
name: { kind: 'Name', value: 'limit' },
value: {
kind: 'Variable',
name: { kind: 'Name', value: 'limit' },
},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'url' } },
{ kind: 'Field', name: { kind: 'Name', value: 'createdAt' } },
],
},
},
],
},
},
],
} as unknown as DocumentNode<PagesQuery, PagesQueryVariables>;
} as unknown as DocumentNode<FreshPagesQuery, FreshPagesQueryVariables>;
export const PageByUrlOnlyDocument = {
kind: 'Document',
definitions: [
Expand Down
7 changes: 4 additions & 3 deletions apps/main/src/server/graphql/page.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ mutation updatePages($projectId: uuid!, $title: String!, $url: String!) {
}
}

# Used in pages/widget/comment/[pageId].tsx
query pages {
pages {
# Used in pages/widget/comment/[pageURL].tsx
query freshPages($limit: Int!) {
pages(order_by: { createdAt: desc }, limit: $limit) {
id
url
createdAt
}
}

Expand Down

1 comment on commit f353ec4

@vercel
Copy link

@vercel vercel bot commented on f353ec4 Sep 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.