[gnome-news/wip/gbsneto/improvements: 4/6] tracker: don't limit the number of fetched items



commit 5198be6d556ecd0e89b6f563e10824cf34f8729a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Mar 5 19:30:47 2016 -0300

    tracker: don't limit the number of fetched items
    
    Tracker should be fast enought to not lag, and we're not
    really working with thusands of feeds right now.

 gnomenews/tracker.py |   21 ++++++++-------------
 gnomenews/view.py    |    6 +++---
 2 files changed, 11 insertions(+), 16 deletions(-)
---
diff --git a/gnomenews/tracker.py b/gnomenews/tracker.py
index 4bc6721..07ba4da 100644
--- a/gnomenews/tracker.py
+++ b/gnomenews/tracker.py
@@ -44,7 +44,7 @@ class Tracker(GObject.GObject):
         self.sparql = Trackr.SparqlConnection.get(None)
 
     @log
-    def get_post_sorted_by_date(self, amount, unread=False, starred=False):
+    def get_post_sorted_by_date(self, unread=False, starred=False):
         query = """
         SELECT
           nie:url(?msg) AS url
@@ -71,8 +71,7 @@ class Tracker(GObject.GObject):
             }
           }
         ORDER BY DESC (nie:contentCreated(?msg))
-        LIMIT %s
-        """ % amount
+        """
 
         results = self.sparql.query(query)
         ret = []
@@ -123,7 +122,7 @@ class Tracker(GObject.GObject):
         """ % (update_interval, url), GLib.PRIORITY_DEFAULT, None)
 
     @log
-    def mark_post_as_read(self, caller, url, data=None):
+    def mark_post_as_read(self, url, data=None):
         """Marks given post as read
 
         Args:
@@ -161,12 +160,11 @@ class Tracker(GObject.GObject):
         self.emit('feeds-updated')
 
     @log
-    def get_posts_for_channel(self, url, amount):
+    def get_posts_for_channel(self, url):
         """Get posts for channel id
 
         Args:
             url (str): URL of the channel.
-            amount (int): number of items to fetch.
             unread (Optional[bool]): return only unread items if True.
         """
         query = """
@@ -187,8 +185,7 @@ class Tracker(GObject.GObject):
                        OPTIONAL { ?creator nco:websiteUrl ?website }}
           }
         ORDER BY DESC (nie:contentCreated(?msg))
-        LIMIT %s
-        """ % (url, amount)
+        """ % url
 
         results = self.sparql.query(query)
         ret = []
@@ -227,13 +224,12 @@ class Tracker(GObject.GObject):
         return ret
 
     @log
-    def get_text_matches(self, text, amount, channel=None):
+    def get_text_matches(self, text, channel=None):
         """Do text search lookup
 
         Args:
             text (str): text to search for.
             channel (str): URL of the channel.
-            amount (int): number of items to fetch.
         """
         query = """
         SELECT
@@ -259,13 +255,12 @@ class Tracker(GObject.GObject):
                        OPTIONAL { ?creator nco:websiteUrl ?website }}
           }
         ORDER BY fts:rank(?msg)
-        LIMIT %d
         """
 
         if channel:
-            query = query % (text, channel, amount)
+            query = query % text, channel
         else:
-            query = query % (text, amount)
+            query = query % text
 
         results = self.sparql.query(query)
         ret = []
diff --git a/gnomenews/view.py b/gnomenews/view.py
index 56de740..46f6b7d 100644
--- a/gnomenews/view.py
+++ b/gnomenews/view.py
@@ -178,7 +178,7 @@ class NewView(GenericFeedsView):
     def update(self, _=None):
         [self.flowbox.remove(old_feed) for old_feed in self.flowbox.get_children()]
 
-        posts = self.tracker.get_post_sorted_by_date(10, unread=True)
+        posts = self.tracker.get_post_sorted_by_date(unread=True)
         [self._add_a_new_preview(post) for post in posts]
         self.show_all()
 
@@ -235,7 +235,7 @@ class FeedsView(GenericFeedsView):
         flowbox.get_style_context().add_class('feeds-list')
         flowbox.connect('child-activated', self._post_activated)
         flowbox.show()
-        posts = self.tracker.get_posts_for_channel(feed['url'], 10)
+        posts = self.tracker.get_posts_for_channel(feed['url'])
         [self._add_a_new_preview(post, flowbox) for post in posts]
 
         if not feed['title']:
@@ -394,7 +394,7 @@ class SearchView(GenericFeedsView):
         if len(self.search_query) is 0:
             return
 
-        posts = self.tracker.get_text_matches(self.search_query, 10)
+        posts = self.tracker.get_text_matches(self.search_query)
         [self._add_a_new_preview(post) for post in posts]
         self.show_all()
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]