summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/printing/pcap.c6
-rw-r--r--source3/printing/printer_list.c26
-rw-r--r--source3/printing/printer_list.h2
3 files changed, 34 insertions, 0 deletions
diff --git a/source3/printing/pcap.c b/source3/printing/pcap.c
index 2e544b7cdc..3bc8e9e4e2 100644
--- a/source3/printing/pcap.c
+++ b/source3/printing/pcap.c
@@ -121,6 +121,12 @@ void pcap_cache_reload(struct tevent_context *ev,
return;
}
+ if (!printer_list_need_refresh()) {
+ /* has been just refeshed, skip */
+ DEBUG(5, ("Refresh just happend, skipping.\n"));
+ return;
+ }
+
status = printer_list_mark_reload();
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("Failed to mark printer list for reload!\n"));
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;
diff --git a/source3/printing/printer_list.h b/source3/printing/printer_list.h
index 5772fbaaa3..a5e7993ed0 100644
--- a/source3/printing/printer_list.h
+++ b/source3/printing/printer_list.h
@@ -39,4 +39,6 @@ NTSTATUS printer_list_clean_old(void);
NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, void *),
void *private_data);
+bool printer_list_need_refresh(void);
+
#endif /* _PRINTER_LIST_H_ */