Skip to content

Commit

Permalink
Don't push too young trees to OSM
Browse files Browse the repository at this point in the history
  • Loading branch information
umonkey committed Jan 9, 2025
1 parent d7e2ecb commit 6319ae2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions backend/src/handlers/osm_push_handler.rs
Original file line number Diff line number Diff line change
@@ -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<OsmClient>,
osm_trees: Arc<OsmTreeRepository>,
Expand Down Expand Up @@ -70,14 +74,21 @@ impl OsmPushHandler {

async fn get_new_trees(&self) -> Result<Vec<TreeRecord>> {
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;
}
}

Expand Down

0 comments on commit 6319ae2

Please sign in to comment.