From f7cce79f70f0801b1ff5aa5271eb973ae38753ea Mon Sep 17 00:00:00 2001 From: syui Date: Fri, 27 Feb 2026 18:44:59 +0900 Subject: [PATCH] fix limit --- .../ai.syui.log.chat/index.json | 26 ++++++- src/commands/sync.rs | 72 ++++++++++++++----- src/types.rs | 1 - 3 files changed, 78 insertions(+), 21 deletions(-) diff --git a/public/content/did:plc:6qyecktefllvenje24fcxnie/ai.syui.log.chat/index.json b/public/content/did:plc:6qyecktefllvenje24fcxnie/ai.syui.log.chat/index.json index e433ca7..dbdf980 100644 --- a/public/content/did:plc:6qyecktefllvenje24fcxnie/ai.syui.log.chat/index.json +++ b/public/content/did:plc:6qyecktefllvenje24fcxnie/ai.syui.log.chat/index.json @@ -98,5 +98,27 @@ "3mfsyvyfq3x2d", "3mfsyvpe72g2b", "3mfsycszf2y27", - "3mfsxkrpkcn25" -] \ No newline at end of file + "3mfsxkrpkcn25", + "3mfswma2hvj23", + "3mf6ej4dnle2h", + "3mf6ed2zvxb2f", + "3mf6duofofy2d", + "3mf6dmhxvbv2b", + "3mf6dg2mfm627", + "3mf6czldksn25", + "3mf6cjbkuq323", + "3mebae7z77x2b", + "3meb7ykzumg27", + "3meb7w4vuas25", + "3meb7bdy3ge23", + "3me6uf4masj2f", + "3me6uc233ib2d", + "3me6u76knjf2b", + "3me6u2g7izx27", + "3me6ttgsk2g25", + "3me6tlrez7l23", + "325sghcecgzco", + "2ks46vomw4s2i", + "2ivbc5b4um5bu", + "255k3bskheo6j" +] diff --git a/src/commands/sync.rs b/src/commands/sync.rs index 1c72190..af3f647 100644 --- a/src/commands/sync.rs +++ b/src/commands/sync.rs @@ -145,23 +145,37 @@ pub async fn sync_to_local( } } - // 3. Sync collection records - let records_url = format!( - "{}?repo={}&collection={}&limit=100", - lexicons::url(pds_host, &com_atproto_repo::LIST_RECORDS), - did, - collection - ); - let res = client.get(&records_url).send().await?; - if res.status().is_success() { - let list: ListRecordsResponse = res.json().await?; - let collection_dir = format!("{}/{}", did_dir, collection); - fs::create_dir_all(&collection_dir)?; + // 3. Sync collection records (with pagination) + let collection_dir = format!("{}/{}", did_dir, collection); + fs::create_dir_all(&collection_dir)?; + + let mut fetched_rkeys: Vec = Vec::new(); + let mut cursor: Option = None; + let mut total_fetched = 0; + + loop { + let mut records_url = format!( + "{}?repo={}&collection={}&limit=100", + lexicons::url(pds_host, &com_atproto_repo::LIST_RECORDS), + did, + collection + ); + if let Some(ref c) = cursor { + records_url.push_str(&format!("&cursor={}", c)); + } + + let res = client.get(&records_url).send().await?; + if !res.status().is_success() { + println!("Failed to fetch records: {}", res.status()); + break; + } + + let list: ListRecordsResponse = res.json().await?; + let count = list.records.len(); - let mut rkeys: Vec = Vec::new(); for record in &list.records { let rkey = record.uri.split('/').next_back().unwrap_or("unknown"); - rkeys.push(rkey.to_string()); + fetched_rkeys.push(rkey.to_string()); let record_path = format!("{}/{}.json", collection_dir, rkey); let record_json = serde_json::json!({ "uri": record.uri, @@ -172,15 +186,37 @@ pub async fn sync_to_local( println!("Saved: {}", record_path); } - // Create index.json with list of rkeys + total_fetched += count; + + match list.cursor { + Some(c) if count > 0 => cursor = Some(c), + _ => break, + } + } + + if total_fetched > 0 { + // Merge with existing index.json to preserve local-only entries let index_path = format!("{}/index.json", collection_dir); - fs::write(&index_path, serde_json::to_string_pretty(&rkeys)?)?; + let mut merged_rkeys = fetched_rkeys.clone(); + + if let Ok(existing) = fs::read_to_string(&index_path) { + if let Ok(existing_rkeys) = serde_json::from_str::>(&existing) { + let fetched_set: std::collections::HashSet = + merged_rkeys.iter().cloned().collect(); + for rkey in existing_rkeys { + if !fetched_set.contains(&rkey) { + merged_rkeys.push(rkey); + } + } + } + } + + fs::write(&index_path, serde_json::to_string_pretty(&merged_rkeys)?)?; println!("Saved: {}", index_path); println!( "Synced {} records from {}", - list.records.len(), - collection + total_fetched, collection ); } diff --git a/src/types.rs b/src/types.rs index fcddaf5..776ff33 100644 --- a/src/types.rs +++ b/src/types.rs @@ -30,7 +30,6 @@ pub struct PutRecordResponse { pub struct ListRecordsResponse { pub records: Vec, #[serde(default)] - #[allow(dead_code)] pub cursor: Option, }