Add an early return if a time slot is already filled
This commit is contained in:
parent
66e7af28eb
commit
871b35c233
2 changed files with 24 additions and 0 deletions
|
|
@ -80,6 +80,18 @@ impl TimeIntervalTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if the bucket for the given timestamp is already full.
|
||||||
|
/// This is a non-mutating check used to skip processing early.
|
||||||
|
pub fn is_full(&self, timestamp: &str) -> bool {
|
||||||
|
let key = self.bucket_key(timestamp);
|
||||||
|
let buckets = self.buckets.read().unwrap();
|
||||||
|
if let Some(counter) = buckets.get(&key) {
|
||||||
|
counter.load(Ordering::SeqCst) >= self.max_photos
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Compute the bucket key from a timestamp string.
|
/// Compute the bucket key from a timestamp string.
|
||||||
fn bucket_key(&self, timestamp: &str) -> String {
|
fn bucket_key(&self, timestamp: &str) -> String {
|
||||||
// Parse date from ISO 8601 timestamp (e.g. "2024-01-15" or "2024-01-15T12:34:56Z")
|
// Parse date from ISO 8601 timestamp (e.g. "2024-01-15" or "2024-01-15T12:34:56Z")
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,18 @@ pub async fn process_single_asset(
|
||||||
// Create pipeline context
|
// Create pipeline context
|
||||||
let mut ctx = PipelineContext::new(asset_id.clone(), timestamp.clone(), face_data.clone());
|
let mut ctx = PipelineContext::new(asset_id.clone(), timestamp.clone(), face_data.clone());
|
||||||
|
|
||||||
|
// Early check: skip if the time slot is already full (avoids wasting processing time)
|
||||||
|
if let Some(tracker) = time_interval {
|
||||||
|
if tracker.is_full(×tamp) {
|
||||||
|
tracing::debug!("Asset {} skipped early: time slot already full (timestamp: {})", asset_id, timestamp);
|
||||||
|
skip_stats.increment("time_interval");
|
||||||
|
return AssetProcessResult::Skipped {
|
||||||
|
asset_id: asset_id.clone(),
|
||||||
|
reason: "Time interval too short".to_string(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check before download (potentially slow)
|
// Check before download (potentially slow)
|
||||||
if cancel_token.is_cancelled() {
|
if cancel_token.is_cancelled() {
|
||||||
return AssetProcessResult::Cancelled {
|
return AssetProcessResult::Cancelled {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue