coldsweat icon indicating copy to clipboard operation
coldsweat copied to clipboard

Optimize database queries

Open passiomatic opened this issue 11 years ago • 1 comments

Several queries spawn quite a lot of subqueries due to the way they are constructed. The obvious ones in fever.py are:

  • get_feeds, see feed.icon.id
  • get_feed_groups, see s.feed.id

The underlying problem is that xxx.icon.id and xxx.feed.id fields are not formally retrieved by Peewee, even if they are there in the record, so an extra query per row is performed.

The Peewee .switch(model) method could do the trick: http://peewee.readthedocs.org/en/latest/peewee/api.html#Query.switch

passiomatic avatar Jul 20 '13 09:07 passiomatic

One more optimization could be this: every time an entry listing is displayed the system requires the list of saved ids, read ids and the unread|saved|all entry listing.

A more optimized query could retrieve the unread entries and also perform a left outer join on Saved model to figure out which entry are saved or not.

In the same vein another query could retrieve the saved entries and also perform a left outer join on Read model to figure out which entry have been read or not.

Finally the query to retrieve all entries could both left outer join Saved and Read models.

passiomatic avatar Jan 31 '14 10:01 passiomatic