snapshot
¶
Persistent library snapshot and delta cache management.
LibrarySnapshotService
¶
Service providing persistent library snapshot and delta caching.
Source code in src/services/cache/snapshot.py
initialize
async
¶
Ensure directories exist and clean up stale formats.
load_snapshot
async
¶
Load snapshot from disk.
Source code in src/services/cache/snapshot.py
save_snapshot
async
¶
Persist snapshot and return its hash.
Source code in src/services/cache/snapshot.py
is_snapshot_valid
async
¶
Check whether snapshot meets freshness and integrity requirements.
Priority logic: 1. If library_mtime unchanged → snapshot valid (ignore age) 2. If library_mtime changed → check age and other constraints
Source code in src/services/cache/snapshot.py
get_snapshot_metadata
async
¶
Load snapshot metadata.
Source code in src/services/cache/snapshot.py
update_snapshot_metadata
async
¶
Persist snapshot metadata.
Source code in src/services/cache/snapshot.py
load_delta
async
¶
Load delta cache.
Source code in src/services/cache/snapshot.py
save_delta
async
¶
Persist delta cache.
Source code in src/services/cache/snapshot.py
get_library_mtime
async
¶
Return modification time of the music library file.
Returns a naive UTC datetime for consistency with snapshot comparisons. Uses UTC to prevent false positives on non-UTC local timezones.
Source code in src/services/cache/snapshot.py
compute_smart_delta
async
¶
Compute track delta using Hybrid Smart Delta approach.
Two modes: - Fast mode (default): Detects new/removed by ID comparison only (~1-2s) - Force mode: Full metadata comparison for manual change detection (~30-60s)
Force mode triggers when: - Force=True (CLI --force) - Last force scan was 7+ days ago (weekly auto-force)
Fast mode (skips full scan) when: - First run (nothing to compare against) - Force scan was within last 7 days
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
applescript_client
|
AppleScriptClientProtocol
|
AppleScriptClient instance for fetching tracks |
required |
force
|
bool
|
CLI --force flag |
False
|
Returns:
| Type | Description |
|---|---|
TrackDelta | None
|
TrackDelta with new/updated/removed track IDs, or None if snapshot unavailable |
Source code in src/services/cache/snapshot.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
is_enabled
¶
is_delta_enabled
¶
clear_snapshot
¶
Delete the snapshot file to force fresh data fetch from Music.app.
Returns:
| Type | Description |
|---|---|
bool
|
True if snapshot was deleted, False if it didn't exist. |
Source code in src/services/cache/snapshot.py
should_force_scan
async
¶
Determine if full metadata scan is needed.
Force scan triggers when: - Force_flag is True (CLI --force) - Last force scan was 7+ days ago (weekly auto-force)
Fast mode (no full scan) when: - First run (nothing to compare against) - Force scan was within last 7 days
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_flag
|
bool
|
CLI --force flag value |
False
|
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Tuple of (should_force, reason) explaining the decision |
Source code in src/services/cache/snapshot.py
compute_snapshot_hash
staticmethod
¶
Compute deterministic hash for snapshot payload.