This document explains the optimization implemented for the Google Tasks CLI advanced synchronization feature.
The advanced sync process has been optimized to improve performance and reduce unnecessary data transfer. The optimization follows a two-phase approach:
- Full Sync for Empty Databases: When the local database is empty, all remote tasks are pulled and stored directly.
- Incremental Sync for Existing Databases: When the local database contains data, only tasks from a specified time range are pulled.
When the local database is detected as empty, the system performs a full sync:
- All remote tasks are pulled from Google Tasks
- Tasks are stored directly to the main local tables
- No temporary tables or complex comparison logic is used
This approach is efficient for initial setup or when starting fresh with a Google Tasks account.
When the local database contains data, the system performs an incremental sync:
- Check the configured pull data range (default: 90 days)
- Pull only tasks modified within that time range using combined date filters:
completedMin: Tasks completed since the minimum datedueMin: Tasks due since the minimum dateupdatedMin: Tasks updated since the minimum date
- Follow the existing processing workflow with these filtered tasks
To reduce the number of API calls, the system now uses combined filters in a single API call per task list:
- Instead of 3 separate calls per task list (completed, due, updated), we now make 1 call per task list
- Each call includes all three filters, returning tasks that match any of the criteria
- Results are deduplicated by task ID to avoid processing the same task multiple times
To reduce unnecessary processing time:
- Push operations are skipped entirely when there are no tasks to push
- Pull operations are skipped entirely when there are no tasks to pull
- This prevents time-consuming operations when no changes are needed
The sync behavior can be configured using the sync.pull_range_days setting in the configuration file:
sync:
pull_range_days: 90 # Default to 3 monthsUsers can adjust this value to balance between sync performance and data completeness.
- Reduced API Calls: Using combined filters reduces API calls by ~66%
- Faster Sync Times: Processing fewer tasks results in faster synchronization
- Lower Bandwidth Usage: Transferring only necessary data reduces bandwidth consumption
- Improved Performance: Less data to process means better overall performance
- Better API Quota Usage: Fewer API calls help stay within Google Tasks API quotas
- Reduced Idle Processing: Skipping operations when no changes are needed saves CPU time
The optimization is implemented in the AdvancedSyncManager class with two main methods:
- _perform_full_sync(): Handles full sync for empty databases
- _perform_incremental_sync(): Handles incremental sync for existing databases
Date filtering is implemented in the GoogleTasksClient.list_tasks_with_combined_filters() method.
Operation skipping is implemented in:
- _execute_push_operations()
- _execute_pull_operations()
- Smart Range Adjustment: Dynamically adjust the pull range based on user behavior
- Task Importance Filtering: Prioritize important tasks even if they're outside the date range
- Cache Optimization: Store metadata about task lists to further optimize API calls
- Parallel Processing: Process multiple task lists in parallel to reduce overall sync time