算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
typeorm-schema-optimizer【设计与创意】Optimize TypeORM entities for performance, query efficiency, migration safety, and relationship design — analyze decorators, indexes, eager loading, and connection pooling.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Analyze TypeORM entities for performance issues, query inefficiencies, missing indexes, relationship design problems, and migration risks. Use when reviewing TypeORM schemas, optimizing slow queries, or preparing for production scale.
"Optimize my TypeORM entities"
"Check for N+1 queries in my TypeORM code"
"Audit TypeORM indexes and relations"
"Review migration safety for TypeORM changes"
# Find all TypeORM entities
grep -rn "@Entity\|@ViewEntity\|@ChildEntity" src/ | head -20
# Find repositories
grep -rn "extends Repository\|@InjectRepository\|getRepository" src/ | head -20
# Check TypeORM config
cat ormconfig.json 2>/dev/null || cat data-source.ts 2>/dev/null
Column optimization:
nullable: true on required fieldslength on string columns (default is VARCHAR(255) — wasteful or too short?)Index analysis:
Relationship design:
eager: true on relationships (loads every time, often unnecessary)cascade options where needed@ManyToMany without join table customizationonDelete behavior (default is no action)leftJoinAndSelect where data is accessed post-queryfind with deep relations instead of query builder## TypeORM Schema Analysis
**Entities:** 18 | **Relations:** 24 | **Indexes:** 12
### 🔴 Critical (3)
1. **Eager loading loop** — User → Posts (eager) → Author (eager) → Posts...
→ Remove `eager: true` from at least one side
2. **Missing index on FK** — Order.userId has no index
With 500K orders, joins on userId cause full table scans
→ Add `@Index()` on `userId` column
3. **N+1 in getOrders()** — orders.service.ts:34
Loads orders then iterates to access `order.items` individually
→ Use `relations: ['items']` or query builder with join
### 🟡 Improvements (4)
4. 6 entities with `eager: true` — performance risk at scale
5. VARCHAR(255) on `status` fields — use enum type (4 possible values)
6. Missing `onDelete: 'CASCADE'` on child entities
7. No read replica configured (DB CPU at 80%)
### ✅ Good Practices
- Proper use of table inheritance for payment types
- Transaction wrapping for order creation flow
- Soft delete with `@DeleteDateColumn`