Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/pages/uxcg/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
generateQuestionsSeo,
getAdjacentUXCGTitles,
mergeQuestionsLocalization,
slimUXCGQuestions,
} from '@uxcore/lib/helpers';
import { getUXCGSlugPaths } from '@uxcore/lib/paths';
import {
Expand Down Expand Up @@ -289,17 +290,15 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => {
currentSlug: slug,
languageSwitchSlugs,
tags,
questionsTest: questions,
questionsSeo,
title: question?.attributes?.title || '',
mainSeo,
modalData: uxcgData || null,
answerRelatedQuestions: answerRelatedQuestions || null,
questionsLength: sortedQuestions?.length,
questions: sortedQuestions,
allQuestions: questions,
allQuestions: slimUXCGQuestions(questions, locale),
id: question?.attributes.number || null,
biases,
biases: { [locale]: biases[locale as 'en' | 'ru' | 'hy'] ?? [] },
},
revalidate: 5,
};
Expand Down
35 changes: 11 additions & 24 deletions src/pages/uxcg/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { GetStaticProps } from 'next';
import { useRouter } from 'next/router';
import React, { FC, useMemo, useState } from 'react';

import { QuestionType, TagType } from '@uxcore/local-types/data';
import { TRouter } from '@uxcore/local-types/global';

import {
generateQuestionsSeo,
mergeBiasesLocalization,
mergeQuestionsLocalization,
} from '@uxcore/lib/helpers';

import { getStrapiBiases } from '@uxcore/api/biases';
import { getUXCGSeo } from '@uxcore/api/mainPageSeo';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This hunk rewrites the whole import block into one alphabetical list. It drops the grouped, blank-line-separated order that AGENTS.md describes, and it makes a perf PR's diff noisier. Please restore the original grouping and only add slimUXCGQuestions and remove the unused getStrapiBiases and mergeBiasesLocalization imports.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tried restoring the grouped order: the file as it is on main already fails simple-import-sort/imports ("Run autofix to sort these imports!"), and the pre-commit hook runs eslint --fix, so any commit touching this file re-sorts the block. The sorted order is what the repo's lint config produces; keeping it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The whole import block is re-sorted into one flat list: the blank-line groups are gone and next/react moved from the top to the bottom. That has nothing to do with this perf change and breaks the grouped order the sibling pages use (see [slug].tsx). Please restore the original block and make only three edits: add slimUXCGQuestions, drop mergeBiasesLocalization, drop getStrapiBiases.

import { getStrapiQuestions } from '@uxcore/api/questions';
import { getTags } from '@uxcore/api/tags';

import SeoGenerator from '@uxcore/components/SeoGenerator';
import Spinner from '@uxcore/components/Spinner';

import UXCGLayout from '@uxcore/layouts/UXCGLayout';
import {
generateQuestionsSeo,
mergeQuestionsLocalization,
slimUXCGQuestions,
} from '@uxcore/lib/helpers';
import { QuestionType, TagType } from '@uxcore/local-types/data';
import { TRouter } from '@uxcore/local-types/global';
import { GetStaticProps } from 'next';
import { useRouter } from 'next/router';
import React, { FC, useMemo, useState } from 'react';

interface UxcgProps {
tags: TagType[];
Expand Down Expand Up @@ -72,12 +66,6 @@ export default Index;
export const getStaticProps: GetStaticProps = async ({ locale }) => {
const tags = getTags();
const questions = await getStrapiQuestions();
const biases = await getStrapiBiases();
const sortedBiases = mergeBiasesLocalization(
biases.en,
biases.ru,
biases.hy,
).sort((a, b) => a.number - b.number);
// HYTranslation TODO
const sortedQuestions = mergeQuestionsLocalization(
questions.en,
Expand All @@ -91,11 +79,10 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => {

return {
props: {
biases: sortedBiases,
tags,
questionsSeo,
mainSeo,
allQuestions: questions,
allQuestions: slimUXCGQuestions(questions, locale),
},
revalidate: 5,
};
Expand Down
21 changes: 21 additions & 0 deletions src/uxcore/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,24 @@ export const getAdjacentUXCGTitles = (locale, uxcgDats, activeQuestion) => {
next: nextQuestion ? `${nextQuestion.slug}` : null,
};
};

// UXCG pages ship every locale's questions so search can match aliases in any
// language. Only the current locale is rendered; the others keep the fields
// search reads, which cuts each page's data by several hundred KB.
export const slimUXCGQuestions = (
questions: Record<'en' | 'ru' | 'hy', any[]>,
locale: string,
) =>
Object.fromEntries(
Object.entries(questions).map(([key, list]) => [
key,
key === locale
? list
: (list || []).map(({ attributes }) => ({
attributes: {
number: attributes?.number ?? null,
aliases: attributes?.aliases ?? null,
},
})),
]),
);
Loading