Keep needs_update() from hitting the shelf
authorJack Miller <jack@codezen.org>
Mon, 17 Nov 2014 07:47:36 +0000 (01:47 -0600)
committerJack Miller <jack@codezen.org>
Mon, 17 Nov 2014 15:54:42 +0000 (09:54 -0600)
Keep a timestamp in memory instead of just in the shelf itself.

Also fixes the high CPU usage introduced in the previous commit.

canto_next/canto_backend.py
canto_next/feed.py
canto_next/fetch.py

index 36b4c23..83190da 100644 (file)
@@ -602,15 +602,11 @@ class CantoBackend(PluginHandler, CantoServer):
             # them if necessary.
 
             if (not self.no_fetch or self.fetch_manual):
-                feed_lock.acquire_read()
-
                 self.fetch.fetch(self.fetch_force, False)
 
                 self.fetch_manual = False
                 self.fetch_force = False
 
-                feed_lock.release_read()
-
             call_hook("daemon_end_loop", [])
 
             time.sleep(1)
index 5689f84..694d68a 100644 (file)
@@ -163,6 +163,8 @@ class CantoFeed(PluginHandler):
         self.keep_unread = keep_unread
         self.stopped = False
 
+        self.last_update = 0
+
         # This is held by the update thread, as well as any get / set attribute
         # threads
 
index 6acfac4..4e40d11 100644 (file)
@@ -53,6 +53,8 @@ class CantoFetchThread(PluginHandler, Thread):
             self.feed.index({"entries" : []})
             return
 
+        self.feed.last_update = time.time()
+
         # Otherwise, actually try to get an update.
 
         extra_headers = { 'User-Agent' :\
@@ -110,7 +112,7 @@ class CantoFetchThread(PluginHandler, Thread):
             update_contents["bozo_exception"] = None
 
         # Update timestamp
-        update_contents["canto_update"] = time.time()
+        update_contents["canto_update"] = self.feed.last_update
 
         update_contents = json.loads(json.dumps(update_contents))
 
@@ -142,22 +144,10 @@ class CantoFetch():
         self.threads = []
 
     def needs_update(self, feed):
-        if feed.URL not in self.shelf:
-            log.info("Empty feed, attempt to update.")
-            return True
-
-        needs_update = True
-
-        f = self.shelf[feed.URL]
-        if "canto_update" not in f:
-            log.warn("No canto_update in feed w/ URL: %s" % feed.URL)
-            return True
-
-        passed = time.time() - f["canto_update"]
+        passed = time.time() - feed.last_update
         if passed < feed.rate * 60:
-            needs_update = False
-
-        return needs_update
+            return False
+        return True
 
     def still_working(self, URL):
         for thread, workingURL in self.threads: