s3-printing: Add method to skip refresh if just happned.
authorSimo Sorce <ssorce@redhat.com>
Fri, 14 May 2010 19:49:29 +0000 (15:49 -0400)
committerAndreas Schneider <asn@samba.org>
Wed, 15 Sep 2010 10:53:40 +0000 (12:53 +0200)
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 <asn@cynapses.org>
source3/printing/pcap.c
source3/printing/printer_list.c
source3/printing/printer_list.h

index 2e544b7cdc373528e0ac5cedf6125795c704eb2a..3bc8e9e4e29334bb6168761e2787f673670015a4 100644 (file)
@@ -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"));
index 123749cf46feff0d5f30f82b94f0cc5be020110a..6392755cf5ae15eb7011648fb0697c7824bc527e 100644 (file)
@@ -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;
index 5772fbaaa33dac08ccf0c74be705293350881ffa..a5e7993ed09a2dae3aa438b5672f73bc3b55ad1d 100644 (file)
@@ -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_ */