check-batch-processing
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "check-batch-processing":https://skillpi.com/zh/skills/deepskill-b8065f2c971e9d4cd914491b4d50f859e3560e23c7669c9a5e23f513968ce1a0。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
分析 PHP 代码中的批处理问题,检测将单项操作用于可批量处理的场景、缺失的批量插入、循环内的单次 API 调用以及高事务开销等问题。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 输入和输出
- 减记
- 实测状态
- 未测试
文件浏览
Frontmatter
name: check-batch-processing
description: Analyzes PHP code for batch processing issues. Detects single-item vs bulk operations, missing batch inserts, individual API calls in loops, transaction overhead.Batch Processing Analysis
Analyze PHP code for batch processing opportunities.
Detection Patterns
1. Single-Item vs Bulk Operations
// SLOW: Individual inserts
foreach ($users as $user) {
$pdo->query("INSERT INTO users (name, email) VALUES ('$name', '$email')");
}
// FAST: Bulk insert
$values = [];
$params = [];
foreach ($users as $i => $user) {
$values[] = "(:name{$i}, :email{$i})";
$params["name{$i}"] = $user['name'];
$params["email{$i}"] = $user['email'];
}
$sql = "INSERT INTO users (name, email) VALUES " . implode(', ', $values);
$pdo->prepare($sql)->execute($params);
2. Individual Database Operations
// SLOW: Save each entity separately
foreach ($entities as $entity) {
$this->em->persist($entity);
$this->em->flush();
}
// FAST: Batch persist and single flush
foreach ($entities as $entity) {
$this->em->persist($entity);
}
$this->em->flush();
// FAST: With memory management for large batches
$batchSize = 100;
foreach ($entities as $i => $entity) {
$this->em->persist($entity);
if ($i % $batchSize === 0) {
$this->em->flush();
$this->em->clear();
}
}
$this->em->flush();
3. Individual API Calls in Loops
// SLOW: HTTP call per item
foreach ($products as $product) {
$price = $this->pricingApi->getPrice($product->getSku());
$product->setPrice($price);
}
// FAST: Batch API call
$skus = array_map(fn($p) => $p->getSku(), $products);
$prices = $this->pricingApi->getPrices($skus);
foreach ($products as $product) {
$product->setPrice($prices[$product->getSku()]);
}
// SLOW: Individual notifications
foreach ($users as $user) {
$this->emailService->send($user->getEmail(), $message);
}
// FAST: Batch send
$emails = array_map(fn($u) => $u->getEmail(), $users);
$this->emailService->sendBatch($emails, $message);
4. Transaction Overhead
// SLOW: Transaction per operation
foreach ($transfers as $transfer) {
$this->connection->beginTransaction();
try {
$this->processTransfer($transfer);
$this->connection->commit();
} catch (Exception $e) {
$this->connection->rollBack();
}
}
// FAST: Single transaction (if appropriate)
$this->connection->beginTransaction();
try {
foreach ($transfers as $transfer) {
$this->processTransfer($transfer);
}
$this->connection->commit();
} catch (Exception $e) {
$this->connection->rollBack();
}
// BALANCED: Chunked transactions
$chunks = array_chunk($transfers, 100);
foreach ($chunks as $chunk) {
$this->connection->beginTransaction();
try {
foreach ($chunk as $transfer) {
$this->processTransfer($transfer);
}
$this->connection->commit();
} catch (Exception $e) {
$this->connection->rollBack();
}
}
5. Individual File Operations
// SLOW: Separate file writes
foreach ($lines as $line) {
file_put_contents($path, $line . "\n", FILE_APPEND);
}
// FAST: Batch write
$content = implode("\n", $lines);
file_put_contents($path, $content);
// FAST: Stream for large data
$handle = fopen($path, 'w');
foreach ($lines as $line) {
fwrite($handle, $line . "\n");
}
fclose($handle);
6. Individual Cache Operations
// SLOW: Individual cache calls
foreach ($items as $item) {
$this->cache->set('item:' . $item->getId(), $item);
}
// FAST: Multi-set
$cacheItems = [];
foreach ($items as $item) {
$cacheItems['item:' . $item->getId()] = $item;
}
$this->cache->setMultiple($cacheItems);
// SLOW: Individual gets
$results = [];
foreach ($ids as $id) {
$results[$id] = $this->cache->get('item:' . $id);
}
// FAST: Multi-get
$keys = array_map(fn($id) => 'item:' . $id, $ids);
$results = $this->cache->getMultiple($keys);
7. Queue Message Publishing
// SLOW: Individual publish
foreach ($events as $event) {
$this->queue->publish($event);
}
// FAST: Batch publish
$this->queue->publishBatch($events);
// With RabbitMQ
$channel->batch_basic_publish();
foreach ($messages as $message) {
$channel->batch_basic_publish($message, $exchange, $routingKey);
}
$channel->publish_batch();
8. Update vs Bulk Update
// SLOW: Individual updates
foreach ($users as $user) {
$user->setStatus('inactive');
$this->em->flush();
}
// FAST: Bulk DQL update
$this->em->createQuery(
'UPDATE User u SET u.status = :status WHERE u.id IN (:ids)'
)->setParameters([
'status' => 'inactive',
'ids' => array_map(fn($u) => $u->getId(), $users)
])->execute();
Grep Patterns
# flush() in loop
Grep: "foreach.*->flush\(\)" --glob "**/*.php"
# API/HTTP calls in loop
Grep: "foreach.*->(request|get|post|send)\(" --glob "**/*.php"
# file_put_contents with APPEND in loop
Grep: "foreach.*file_put_contents.*FILE_APPEND" --glob "**/*.php"
# cache->set in loop
Grep: "foreach.*->set\(" --glob "**/*.php"
# Individual INSERT
Grep: "foreach.*INSERT INTO" --glob "**/*.php"
Batch Size Guidelines
| Operation | Recommended Batch Size |
|---|---|
| Database inserts | 100-1000 |
| Doctrine flush | 50-100 |
| API calls | Depends on API limits |
| Cache operations | 100-500 |
| File writes | Buffer in memory, single write |
| Queue publish | 100-500 |
Severity Classification
| Pattern | Severity |
|---|---|
| Individual DB operations in loop | 🔴 Critical |
| HTTP calls in loop | 🔴 Critical |
| flush() per entity | 🟠 Major |
| Individual cache operations | 🟠 Major |
| Individual file appends | 🟡 Minor |
Output Format
### Batch Processing Issue: [Description]
**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Type:** [Individual DB|API Loop|Transaction Overhead|...]
**Issue:**
[Description of the batch processing problem]
**Current:** N operations in loop
**Optimal:** 1 batch operation
**Code:**
```php
// Individual operations
Optimization:
// Batch operation
Improvement: For 1000 items:
- Network round trips: 1000 → 1
- Execution time: ~10s → ~100ms
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
待提升项
-
缺少 When to Use 章节 原报告严重程度:轻微
文档未明确说明适用场景和使用时机
改进建议:建议添加 When to Use 章节,说明何时使用此 Skill 进行分析
亮点
- 提供 PHP 代码批处理优化分析,解决开发者性能痛点
- 覆盖数据库、API、缓存、文件操作等多个批处理场景
亮点
- description 明确描述功能边界,触发词完整
- 提供多种 grep 模式便于实际使用
待提升项
-
文档过长 原报告严重程度:轻微
文档约 600 行,超出推荐长度
改进建议:建议将部分内容拆分为独立文件或提供摘要版本
亮点
- 结构清晰,包含检测模式、代码示例、优化建议
- frontmatter 完整,输出格式规范
待提升项
-
缺少集成说明 原报告严重程度:轻微
未说明如何集成到实际开发工作流
改进建议:建议提供自动化检测脚本或 CI/CD 集成示例
亮点
- 提供具体代码示例和 grep 模式
- 覆盖事务回滚、内存管理等异常场景
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。