Files
agent-park/src/hooks/AGENTS.md
T
mzaxd 6cb4545a17 chore: 更新项目文档和工具状态
- 更新 AGENTS.md 项目知识库文档(多目录)
- 添加 docs/analyst.md 产品分析文档
- 添加 .omc/ 工具状态和会话记录
- 添加 .sisyphus/ 计划文档
- 添加 project-structure.txt 项目结构
- 删除 timeline 测试截图
2026-02-20 21:48:05 +08:00

2.0 KiB

src/hooks/ - Server-Side Data Fetching

Purpose: Server-side data fetching functions (NOT React hooks). Exported functions for use in Server Components and API routes.

Architecture

  • Server Functions Only: No React hooks, no client-side state
  • Direct Prisma Queries: ORM queries with optimization patterns
  • ISR Support: Used by Next.js App Router for incremental static revalidation

Key Functions

Project Data (useProjects.ts)

  • getProjects(): List projects with tags, pagination, filtering (search/tags/status)
    • Flattens ProjectTag junction table to return tags directly
    • Optimized for list queries with selective field loading
  • getProjectBySlug(slug): Get single project by slug
    • Used by ISR pages with 5-min revalidation
    • Includes all tags and external links
  • getAllTags(): All tags with project counts
  • getTagsWithProjectCounts(): Tags sorted by popularity (count DESC)

Keyword Cloud (useKeywordCloud.ts)

  • getAllQuarters(): List all quarters with metadata
  • getQuarterByQuarter(quarter): Single quarter with keyword count
  • getKeywordsByQuarter(quarter): All keywords for a quarter
  • getVisualStyleRules(): Visual style configuration for word cloud

Query Optimization Patterns

N+1 Prevention: Batch queries for related data (tags, links) Selective Loading: Only fetch required fields via Prisma select Index Utilization: Leverages database indexes (status+createdAt, slug, etc.) Pagination: Limit/offset to prevent large result sets

ISR Strategy

  • Revalidation: 5-minute revalidate on project detail pages
  • Stale Data Acceptable: Project listings tolerate slight staleness
  • Cache Busting: Use revalidatePath() when data changes via webhook

Best Practices

  • Always import via @/hooks/use* (not relative paths)
  • Return plain objects/arrays, never Prisma model instances
  • Handle errors at route level, not in these functions
  • Add new functions to existing files or create new use*.ts files