From 6319ae230a2dfab5cc8c96a746d90d9701cec160 Mon Sep 17 00:00:00 2001 From: Justin Forest Date: Thu, 9 Jan 2025 17:10:44 +0400 Subject: [PATCH] Don't push too young trees to OSM --- backend/src/handlers/osm_push_handler.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/src/handlers/osm_push_handler.rs b/backend/src/handlers/osm_push_handler.rs index 8b0a0c86..c2ec1d9e 100644 --- a/backend/src/handlers/osm_push_handler.rs +++ b/backend/src/handlers/osm_push_handler.rs @@ -1,11 +1,15 @@ use crate::common::database::repositories::*; use crate::services::*; use crate::types::*; +use crate::utils::get_timestamp; use log::info; use std::sync::Arc; const MAX_CHANGES: usize = 100; +// Don't push trees younget than 10 minutes, let users finish their surveys. +const MIN_AGE: u64 = 600; + pub struct OsmPushHandler { osm: Arc, osm_trees: Arc, @@ -70,14 +74,21 @@ impl OsmPushHandler { async fn get_new_trees(&self) -> Result> { let mut res = Vec::new(); + let max_ts = get_timestamp() - MIN_AGE; for tree in self.trees.all().await? { - if self.shall_add(&tree) { - res.push(tree); + if !self.shall_add(&tree) { + continue; + } + + if tree.added_at > max_ts { + continue; + } + + res.push(tree); - if res.len() == MAX_CHANGES { - break; - } + if res.len() == MAX_CHANGES { + break; } }