Skip to content

[WIP] Optimize bulk operation method for better performance - #379

Closed
hotlong with Copilot wants to merge 1 commit into
mainfrom
copilot/optimize-bulk-operation
Closed

hotlong with Copilot wants to merge 1 commit into
mainfrom
copilot/optimize-bulk-operation

Conversation

Copilot AI commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

ObjectStack Spec: Bulk Operations & Realtime Subscription Support

Summary

Enhance ObjectStack protocol specification to support:

  1. Batch Operations Optimization - Complete bulk operation definitions for efficient data processing
  2. Real-time Subscription Support - WebSocket/SSE based real-time data synchronization

Implementation Plan

Phase 1: Analysis & Documentation

  • Explore existing codebase structure
  • Review current driver interface (driver.zod.ts)
  • Review current API contracts (contract.zod.ts)
  • Review existing realtime protocols (realtime.zod.ts, websocket.zod.ts)
  • Review client implementation (client/src/index.ts)
  • Document current state and gaps

Phase 2: Driver Capabilities Enhancement

  • Add bulkOperations capability flag to DriverCapabilitiesSchema
  • Add realtime capability flag to DriverCapabilitiesSchema
  • Update driver interface documentation for bulk methods
  • Add tests for new capability flags

Phase 3: API Contract Updates

  • Review and enhance bulk operation API contracts
  • Ensure consistency between driver interface and API contracts
  • Add realtime subscription contracts if missing
  • Update contract tests

Phase 4: Client Protocol Enhancement

  • Verify client bulk methods match driver spec
  • Add realtime client interface definitions
  • Document client usage patterns
  • Add TypeScript examples

Phase 5: Testing & Validation

  • Run existing test suite
  • Add/update tests for bulk operations
  • Add/update tests for realtime subscriptions
  • Validate all schemas compile correctly
  • Review for security vulnerabilities

Phase 6: Final Review

  • Code review
  • Security scan with CodeQL
  • Documentation completeness check
  • Final validation
Original prompt

B. 批量操作优化

现状: bulk() 方法逐个处理记录
问题:

❌ N+1 查询问题(update 操作)
❌ 无事务支持
❌ 错误处理不友好
优化方案:

// 利用 ObjectStack Client 的批量 API
async bulk(resource: string, operation: 'create' | 'update' | 'delete', data: Partial[]) {
await this.connect();

try {
switch (operation) {
case 'create':
return await this.client.data.createMany(resource, data);
case 'update':
// 使用批量更新而非逐个更新
return await this.client.data.updateMany(resource, data);
case 'delete':
const ids = data.map(item => (item as any).id);
await this.client.data.deleteMany(resource, ids);
return [];
}
} catch (error) {
// 添加部分成功处理
throw new BulkOperationError(error, operation, data);
}
}
需要 @objectstack/client 支持:

✅ createMany() - 已存在
✅ deleteMany() - 已存在
❌ updateMany() - 需要新增 或提供批量 patch API
C. 实时订阅支持

现状: 仅支持轮询刷新
需求: WebSocket/SSE 实时数据更新

架构设计:

// packages/data-objectstack/src/RealtimeAdapter.ts
export class RealtimeObjectStackAdapter extends ObjectStackAdapter {
private subscriptions = new Map<string, Subscription>();

// 订阅资源变更
subscribe(resource: string, params?: QueryParams, callback: (data: any) => void) {
const ws = this.client.realtime.subscribe(resource, params);
ws.on('change', callback);
this.subscriptions.set(${resource}:${JSON.stringify(params)}, ws);
return () => ws.close();
}

// 取消所有订阅
unsubscribeAll() {
this.subscriptions.forEach(sub => sub.close());
this.subscriptions.clear();
}
}
需要 @objectstack/client 支持:

新增 client.realtime API
WebSocket 连接管理
事件类型: 'create' | 'update' | 'delete'
订阅过滤器支持


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel

vercel Bot commented Jan 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jan 30, 2026 9:47am

Request Review

@hotlong hotlong closed this Jan 30, 2026
Copilot AI requested a review from hotlong January 30, 2026 09:43
Copilot stopped work on behalf of hotlong due to an error January 30, 2026 09:43
This was referenced Oct 20, 2026
baozhoutao pushed a commit that referenced this pull request Oct 21, 2026
…utomationResult.userMessage/innerRefusal and FlowFailureDetailsSchema

Ruling B' on #24914 (decision batch #379 item 5).

Claude-Session: https://claude.ai/code/session_01D6F9axfoPzR7t8G1J7Ytzz
Co-authored-by: Claude <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 6bd108d2 Deployed Jan 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants