def posts(self, categories=None): """ This method first creates a mapping of feeds to categories, then iterates through the Posts collection, finding only posts with those given feeds (and not dereferencing the related object). This will speed up the post fetch process and give us more information, quickly. The generator therefore yields post, category tuples to provide for the single pass across the posts. This method also counts the number of posts per category. This method raises an exception if not in the correct state. """ if self.state != State.Started: raise ExportError(( "Calling the posts method when not in the started state " "could cause double counting or multiple database reads." )) # Create a mapping of feed id to category feeds = { feed.id: feed.category for feed in self.feeds(categories) } # Iterate through all posts that have the given feed ids without # dereferencing the related object. Yield (post, category) tuples. # This method also counts the number of posts per category. for post in Post.objects(feed__in=feeds.keys()).no_dereference().no_cache(): category = feeds[post.feed.id] self.counts[category] += 1 yield post, category
def posts(self, categories=None): """ Returns a set of posts for the given category """ for feed in self.feeds(categories): for post in Post.objects(feed=feed): yield post
def posts(self, categories=None): """ This method first creates a mapping of feeds to categories, then iterates through the Posts collection, finding only posts with those given feeds (and not dereferencing the related object). This will speed up the post fetch process and give us more information, quickly. The generator therefore yields post, category tuples to provide for the single pass across the posts. This method also counts the number of posts per category. This method raises an exception if not in the correct state. """ if self.state != State.Started: raise ExportError( ("Calling the posts method when not in the started state " "could cause double counting or multiple database reads.")) # Create a mapping of feed id to category feeds = {feed.id: feed.category for feed in self.feeds(categories)} # Iterate through all posts that have the given feed ids without # dereferencing the related object. Yield (post, category) tuples. # This method also counts the number of posts per category. for post in Post.objects( feed__in=feeds.keys()).no_dereference().no_cache(): category = feeds[post.feed.id] self.counts[category] += 1 yield post, category