aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2025-03-07 23:07:18 +0600
committerGitHub <noreply@github.com>2025-03-07 23:07:18 +0600
commit8b01fa63df28233a4468ff5f991a76aad657f747 (patch)
treef4fbbae52f633db9603637569a0944bafc3b14ac
parentef8c6dc213ef2ed6eabcff54289b4b57df52b299 (diff)
parenta63e77fa0c46197b2a04b8e750de32beaf173493 (diff)
downloadrspamd-8b01fa63df28233a4468ff5f991a76aad657f747.tar.gz
rspamd-8b01fa63df28233a4468ff5f991a76aad657f747.zip
Merge pull request #5377 from rspamd/vstakhov-maps-caching
[Feature] Try to check maps earlier if their expires is too long
-rw-r--r--src/libserver/maps/map.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/libserver/maps/map.c b/src/libserver/maps/map.c
index 43a9d5d86..97130ad7c 100644
--- a/src/libserver/maps/map.c
+++ b/src/libserver/maps/map.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2024 Vsevolod Stakhov
+ * Copyright 2025 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -295,6 +295,23 @@ rspamd_map_cache_cb(struct ev_loop *loop, ev_timer *w, int revents)
}
}
+static inline time_t
+rspamd_http_map_process_next_check(time_t now, time_t expires, time_t map_check_interval)
+{
+ static const time_t interval_mult = 16;
+ /* By default use expires header */
+ time_t next_check = expires;
+
+ if (expires < now) {
+ return now;
+ }
+ else if (expires - now > map_check_interval * interval_mult) {
+ next_check = now + map_check_interval * interval_mult;
+ }
+
+ return next_check;
+}
+
static int
http_map_finish(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
@@ -371,10 +388,9 @@ http_map_finish(struct rspamd_http_connection *conn,
hdate = rspamd_http_parse_date(expires_hdr->begin, expires_hdr->len);
if (hdate != (time_t) -1 && hdate > msg->date) {
- cached_timeout = map->next_check - msg->date +
- map->poll_timeout * 2;
-
- map->next_check = hdate;
+ map->next_check = rspamd_http_map_process_next_check(msg->date, hdate,
+ (time_t) map->poll_timeout);
+ cached_timeout = map->next_check - msg->date;
}
else {
msg_info_map("invalid expires header: %T, ignore it", expires_hdr);
@@ -528,7 +544,8 @@ http_map_finish(struct rspamd_http_connection *conn,
hdate = rspamd_http_parse_date(expires_hdr->begin, expires_hdr->len);
if (hdate != (time_t) -1 && hdate > msg->date) {
- map->next_check = hdate;
+ map->next_check = rspamd_http_map_process_next_check(msg->date, hdate,
+ (time_t) map->poll_timeout);
}
else {
msg_info_map("invalid expires header: %T, ignore it", expires_hdr);
@@ -1663,7 +1680,7 @@ rspamd_map_read_http_cached_file(struct rspamd_map *map,
double now = rspamd_get_calendar_ticks();
if (header.next_check > now) {
- map->next_check = header.next_check;
+ map->next_check = rspamd_http_map_process_next_check(now, header.next_check, map->poll_timeout);
}
else {
map->next_check = now;