]> git.phdru.name Git - m_librarian.git/commitdiff
Speedup counting books
authorOleg Broytman <phd@phdru.name>
Sat, 5 Mar 2016 23:10:36 +0000 (02:10 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 5 Mar 2016 23:10:36 +0000 (02:10 +0300)
Count books by author/genre using intermediate tables.

m_librarian/db.py

index ba091f3442286186c4cacb4de619f51078cb25cf..65c79873612025d57bbda38955b8dc97787c0b6b 100755 (executable)
@@ -167,13 +167,13 @@ def insert_author(surname, name, misc_name):
 
 def update_counters():
     for author in Author.select():
-        author.count = len(author.books)
+        author.count = AuthorBook.select(AuthorBook.q.author == author).count()
 
     for ext in Extension.select():
         ext.count = Book.select(Book.q.extension == ext.name).count()
 
     for genre in Genre.select():
-        genre.count = len(genre.books)
+        genre.count = BookGenre.select(BookGenre.q.genre == genre).count()
 
     for language in Language.select():
         language.count = Book.select(Book.q.language == language.name).count()