Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Myers <elizabeth.jennifer.myers@gmail.com>
  • Loading branch information
Elizafox committed Mar 18, 2024
1 parent 1a4f3dd commit cded7db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions service/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ impl Query {
pub async fn fetch_all_urls(db: &DbConn) -> Result<Vec<url::Model>, DbErr> {
Url::find().order_by_asc(url::Column::Id).all(db).await
}

// Find a URL filter by its ID.
pub async fn find_url_filter(db: &DbConn, id: i64) -> Result<Option<url_filter::Model>, DbErr> {
UrlFilter::find_by_id(id).one(db).await
}


// Get all CIDR bans in the database.
// TODO: pagination?
pub async fn fetch_all_cidr_bans(
Expand Down
7 changes: 7 additions & 0 deletions src/bancache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use service::Query;

// This caches IP bans/allows so we don't hit the database so much.

// TODO: configurable
const CACHE_ENTRIES: u64 = 10_000;

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -73,4 +74,10 @@ impl BanCache {
.invalidate_entries_if(move |k, _| network.contains(*k))
.expect("Could not invalidate cache");
}

// Invalidate all bans in the cache
pub(crate) fn invalidate_all(&self) {
trace!("Invalidating entire ban cache");
self.cache.invalidate_all();
}
}

0 comments on commit cded7db

Please sign in to comment.