From 25a2d94974c7befd13f90e52b61e297c31ae52e9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 14 May 2010 15:49:29 -0400 Subject: s3-printing: Add method to skip refresh if just happned. This way if multiple process try to refresh at the same time we don't do it over and over again. Signed-off-by: Andreas Schneider --- source3/printing/printer_list.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source3/printing/printer_list.c') diff --git a/source3/printing/printer_list.c b/source3/printing/printer_list.c index 123749cf46..6392755cf5 100644 --- a/source3/printing/printer_list.c +++ b/source3/printing/printer_list.c @@ -215,6 +215,32 @@ done: return status; } +bool printer_list_need_refresh(void) +{ + NTSTATUS status; + time_t now = time(NULL); + time_t last_refresh; + + status = printer_list_get_last_refresh(&last_refresh); + if (!NT_STATUS_IS_OK(status)) { + return true; + } + + if (now > last_refresh) { + /* if refresh occurred last than 1 seconds ago, + * then we probably don't need to refresh */ + if ((now - last_refresh) < 1) { + return false; + } + } else { + /* last_refresh newer than now, wow, someone just updated the + * cache under our nose, do not do again. */ + return false; + } + + return true; +} + NTSTATUS printer_list_mark_reload(void) { struct db_context *db; -- cgit