microwind/ai-skills/read-model-optimization

Claude Code and agent skill by microwind/ai-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

为查询场景专门设计的数据模型,通过反规范化、物化视图等技术优化读取性能。

Install

npx vskill@latest install microwind/ai-skills/read-model-optimization

SKILL.md

读模型优化 (Read Model Optimization)

概述

读模型是为查询性能专门优化的数据视图,与写模型(领域模型)分离,可以按查询需求自由设计。

优化策略

1. 反规范化
sql
-- 写模型:规范化(多表)
-- orders, order_items, customers, products(4张表,需要JOIN)
-- 读模型:反规范化(一张视图)
CREATE TABLE order_summary_view (
order_id VARCHAR PRIMARY KEY,
customer_name VARCHAR,
customer_email VARCHAR,
total_amount DECIMAL,
item_count INT,
status VARCHAR,
created_at TIMESTAMP
);
-- 查询时零 JOIN,直接读取
2. 事件驱动更新
java
// 监听事件更新读模型
@EventHandler
public class OrderReadModelProjector {
private final JdbcTemplate jdbc;
public void on(OrderPlacedEvent event) {
jdbc.update(
"INSERT INTO order_summary_view (order_id, customer_name, total_amount, status) "
+ "VALUES (?, ?, ?, 'PLACED')",
event.getOrderId(), event.getCustomerName(), event.getTotalAmount()
);
}
public void on(OrderShippedEvent event) {
jdbc.update(
"UPDATE order_summary_view SET status = 'SHIPPED' WHERE order_id = ?",
event.getOrderId()
);
}
}
3. 多种读模型
python
# 同一数据,不同的读模型服务不同场景
# 列表页读模型(Redis Hash)
class OrderListCache:
def get_recent_orders(self, customer_id: str, limit: int = 20):
return self.redis.lrange(f"orders:{customer_id}", 0, limit)
# 搜索读模型(Elasticsearch)
class OrderSearchIndex:
def search(self, keyword: str, filters: dict):
return self.es.search(index="orders", query={"match": {"description": keyword}})
# 报表读模型(数据仓库)
class OrderReportView:
def monthly_sales(self, year_month: str):
return self.warehouse.query(
"SELECT SUM(total) FROM sales_fact WHERE month = %s", year_month)

读模型存储选择

场景推荐存储原因
列表展示Redis / 关系数据库视图快速分页
全文搜索Elasticsearch倒排索引
报表分析数据仓库 / ClickHouse列式存储
实时仪表盘Redis / 时序数据库低延迟

与其他DDD概念的关系

概念关系
CQRS读模型是 CQRS 查询端的核心
事件溯源从事件流投影生成读模型
领域事件事件驱动读模型的更新

总结

核心:为查询场景专门设计数据模型,反规范化优化读取性能。

实践:通过事件驱动更新读模型,不同场景用不同存储。

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
60
Repository forks
15
7-day trend score
21

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 31 Jul 2026, 3 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/microwind/ai-skills/read-model-optimization/badge)](https://verified-skill.com/skills/microwind/ai-skills/read-model-optimization)

Something wrong with this skill or its page? Tell us.