diff --git a/sync.py b/sync.py index 57ed024..05c8519 100644 --- a/sync.py +++ b/sync.py @@ -353,15 +353,18 @@ def get_oldest_unsynced_projects(db, fraction: float = 0.2) -> List[int]: try: projects_ref = db.collection("projects") all_docs = list(projects_ref.stream()) - total = len(all_docs) + + # Exclude archived projects from the sync pool + active_docs = [doc for doc in all_docs if not doc.to_dict().get("is_archived")] + total = len(active_docs) count_to_sync = max(1, int(total * fraction)) # Sort by last_synced_at ascending (empty strings first, then oldest timestamps) - sorted_docs = sorted(all_docs, key=lambda doc: doc.to_dict().get("last_synced_at", "")) + sorted_docs = sorted(active_docs, key=lambda doc: doc.to_dict().get("last_synced_at", "")) selected_docs = sorted_docs[:count_to_sync] result_ids = [int(doc.id) for doc in selected_docs if doc.id and doc.id != "None"] - print(f"[SYNC STRATEGY] {total} projects in Firestore, will sync oldest {len(result_ids)} ({fraction*100:.0f}%)") + print(f"[SYNC STRATEGY] {total} active projects in Firestore, will sync oldest {len(result_ids)} ({fraction*100:.0f}%)") if selected_docs: sample = selected_docs[0].to_dict() print(f"[SYNC STRATEGY] Oldest: ID={result_ids[0]}, last_synced_at='{sample.get('last_synced_at', 'N/A')}'")