Skip to content

Commit

Permalink
perf: only query once
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <zhangtianli2006@163.com>
  • Loading branch information
ZTL-UwU committed Jun 11, 2024
1 parent 4eee460 commit 56f26c8
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 48 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: ESLint Check

on: [workflow_dispatch, push]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 9
run_install: false

- name: Install dependencies
working-directory: .
run: pnpm i

- name: Run Lint
run: pnpm lint --no-fix
29 changes: 29 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Type Check

on: [workflow_dispatch, push]

jobs:
typecheck:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 9
run_install: false

- name: Install dependencies
working-directory: .
run: pnpm i

- name: Install docs deps
working-directory: ./docs
run: pnpm i

- name: Run typecheck
working-directory: .
run: pnpm nuxt typecheck
6 changes: 0 additions & 6 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import drizzle from 'eslint-plugin-drizzle';
import antfu from '@antfu/eslint-config';

export default antfu({
Expand All @@ -12,15 +11,10 @@ export default antfu({
vue: true,
ignores: ['.github/**/*', 'public/**'],
}, {
plugins: {
drizzle,
},
rules: {
'style/brace-style': ['warn', '1tbs', { allowSingleLine: true }],
'vue/block-order': ['error', {
order: ['template', 'script', 'style'],
}],
'drizzle/enforce-delete-with-where': ['error'],
'drizzle/enforce-update-with-where': ['error'],
},
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"@vueuse/nuxt": "^10.10.0",
"drizzle-kit": "^0.22.6",
"eslint": "9.4.0",
"eslint-plugin-drizzle": "^0.2.3",
"nuxt-icon": "^0.6.10",
"tailwindcss": "^3.4.4",
"typescript": "^5.4.5",
"vue-tsc": "^2.0.21",
"wrangler": "^3.60.0"
}
}
13 changes: 7 additions & 6 deletions pages/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ const category = computed(
() => categoryMap.find(x => x.value === slugCategory) || categoryMap[0],
);

const guideList = await $api.guide.query({ primaryCategory: slugCategory });
const data: Map<TSecondaryCategory, RouterOutput['guide']> = new Map();
for (const c of categoryMap.find(x => x.value === slugCategory)?.secondary ?? []) {
const res = await $api.guide.query({
primaryCategory: slugCategory,
secondaryCategory: c.value,
});
if (res)
data.set(c.value, res.sort((a, b) => a.id - b.id));
data.set(
c.value,
guideList
.filter(x => x.secondaryCategory === c.value)
?.sort((a, b) => a.id - b.id),
);
}

useHead({
Expand Down
148 changes: 115 additions & 33 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions server/trpc/routers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ export const appRouter = router({
guide: publicProcedure
.input(z.object({
primaryCategory: primaryCategorySchema,
secondaryCategory: secondaryCategorySchema,
}))
.query(async ({ input }) => {
return await useDrizzle().query.guidebook.findMany({
where: and(
eq(guidebook.primaryCategory, input.primaryCategory),
eq(guidebook.secondaryCategory, input.secondaryCategory),
// --------------- TEST -vvvvv--------------
eq(guidebook.isReviewed, false),
),
Expand Down

0 comments on commit 56f26c8

Please sign in to comment.