From: Oleg Broytman Date: Sat, 5 Mar 2016 23:10:36 +0000 (+0300) Subject: Speedup counting books X-Git-Tag: 0.0.4~50 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=4b5c30e8bbf62ad70791b3b11f57f83f27816583;p=m_librarian.git Speedup counting books Count books by author/genre using intermediate tables. --- diff --git a/m_librarian/db.py b/m_librarian/db.py index ba091f3..65c7987 100755 --- a/m_librarian/db.py +++ b/m_librarian/db.py @@ -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()