offline-sync

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Offline-First & Data Sync Specialist Skill

离线优先与数据同步专家技能

This skill enables the assistant to design and implement a robust synchronization system to solve the "No Offline Queue" issue (P0).
这个技能可帮助助手设计并实现稳健的同步系统,以解决"无离线队列"问题(P0)。

Knowledge Areas

知识领域

1. Local Storage (Native)

1. 本地存储(原生端)

  • Room Database: Implementing a local SQLite storage on the Android side to buffer location updates.
  • Data Entities: Defining schema for
    OfflineLocation
    that matches the Supabase
    registros_reten
    structure.
  • Room Database: 在Android端实现本地SQLite存储,用于缓存位置更新数据。
  • 数据实体: 定义
    OfflineLocation
    的schema,匹配Supabase的
    registros_reten
    结构。

2. Synchronization Strategies

2. 同步策略

  • Background Sync: Using
    WorkManager
    for reliable data upload when connectivity returns.
  • Conflict Resolution: Simple timestamp-based resolution for location data.
  • Batched Uploads: Strategies for sending multiple records in a single HTTP request to Supabase to save battery.
  • 后台同步: 使用
    WorkManager
    在网络恢复时可靠地上传数据。
  • 冲突解决: 针对位置数据采用基于时间戳的简单解决方案。
  • 批量上传: 单次HTTP请求向Supabase发送多条记录的策略,以节省电量。

3. Connection Monitoring

3. 连接状态监控

  • Network State: Reacting to connectivity changes on both the Web (React) and Native (Java) sides.
  • Failover Logic: Gracefully switching between direct-to-Supabase and local-first modes.
  • 网络状态: 在Web(React)和原生(Java)两端响应网络连通性变化。
  • 故障切换逻辑: 在直连Supabase模式和本地优先模式之间平滑切换。

4. Data Integrity

4. 数据完整性

  • De-duplication: Ensuring the same location point isn't sent twice.
  • Queue Management: Truncating old logs if the device is offline for an extended period to prevent storage bloat.
  • 去重: 确保同一个位置点不会被重复发送。
  • 队列管理: 若设备长时间离线,截断旧日志以避免存储膨胀。

Guidelines for Responses

响应指南

  • Prioritize Batched Requests to maximize battery efficiency.
  • Always include Error Handling for network failures in sync logic.
  • Recommend Capacitor SQLite for any complex local storage needs on the web layer.
  • Ensure Data Retention is respected (deleting synced records).
  • 优先采用批量请求以最大化电池效率。
  • 同步逻辑中必须包含针对网络故障的错误处理
  • 若Web层有复杂本地存储需求,推荐使用Capacitor SQLite
  • 确保遵守数据保留规则(删除已同步的记录)。