From 0cae5ac727dfc435e352bb629b119478ed86ad1a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 11 Mar 2023 03:36:59 +0200 Subject: [PATCH 19/19] send_server_info_to_metaserver(): Read timer just once See osdn #46445 Signed-off-by: Marko Lindqvist --- server/meta.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/server/meta.c b/server/meta.c index 72f7b4762f..e890e4239f 100644 --- a/server/meta.c +++ b/server/meta.c @@ -498,6 +498,7 @@ bool send_server_info_to_metaserver(enum meta_flag flag) static struct timer *last_send_timer = NULL; static bool want_update; + int since_previous; if (!server_is_open) { return FALSE; @@ -528,25 +529,31 @@ bool send_server_info_to_metaserver(enum meta_flag flag) return TRUE; } - /* Don't allow the user to spam the metaserver with updates */ - if (last_send_timer && (timer_read_seconds(last_send_timer) - < METASERVER_MIN_UPDATE_INTERVAL)) { - if (flag == META_INFO) { - want_update = TRUE; /* We couldn't update now, but update a.s.a.p. */ - } + if (last_send_timer != NULL) { + since_previous = timer_read_seconds(last_send_timer); - return FALSE; + /* Don't allow the user to spam the metaserver with updates */ + if (since_previous < METASERVER_MIN_UPDATE_INTERVAL) { + if (flag == META_INFO) { + want_update = TRUE; /* We couldn't update now, but update a.s.a.p. */ + } + + return FALSE; + } + } else { + since_previous = MAX(METASERVER_REFRESH_INTERVAL + 1, + METASERVER_MIN_UPDATE_INTERVAL + 1); } /* If we're asking for a refresh, only do so if * we've exceeded the refresh interval */ - if ((flag == META_REFRESH) && !want_update && last_send_timer - && (timer_read_seconds(last_send_timer) < METASERVER_REFRESH_INTERVAL)) { + if ((flag == META_REFRESH) && !want_update + && since_previous < METASERVER_REFRESH_INTERVAL) { return FALSE; } /* Start a new timer if we haven't already */ - if (!last_send_timer) { + if (last_send_timer == NULL) { last_send_timer = timer_new(TIMER_USER, TIMER_ACTIVE, "meta"); } -- 2.39.2