security: add client-side rate limiting to update_all command
This commit is contained in:
@@ -3,6 +3,8 @@ use crate::github::GitHubClient;
|
|||||||
use crate::models::{RateLimitInfo, Repo, SearchResponse, SearchResult};
|
use crate::models::{RateLimitInfo, Repo, SearchResponse, SearchResult};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
|
||||||
pub struct SearchEngine {
|
pub struct SearchEngine {
|
||||||
db: Database,
|
db: Database,
|
||||||
@@ -105,6 +107,12 @@ impl SearchEngine {
|
|||||||
if last_rate_limit.remaining < 3 {
|
if last_rate_limit.remaining < 3 {
|
||||||
println!("\nWarning: Rate limit running low ({} remaining)", last_rate_limit.remaining);
|
println!("\nWarning: Rate limit running low ({} remaining)", last_rate_limit.remaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Client-side rate limiting: wait 3 seconds between requests
|
||||||
|
// This respects both anonymous (10/min = 6s) and authenticated (30/min = 2s) limits
|
||||||
|
if idx < total - 1 {
|
||||||
|
sleep(Duration::from_secs(3)).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("\n✓ Updated {} repositories", total);
|
println!("\n✓ Updated {} repositories", total);
|
||||||
|
|||||||
Reference in New Issue
Block a user