From 4b5c30e8bbf62ad70791b3b11f57f83f27816583 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 6 Mar 2016 02:10:36 +0300 Subject: [PATCH] Speedup counting books Count books by author/genre using intermediate tables. --- m_librarian/db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() -- 2.39.2