openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #14956
[Merge] lp:~googol/openlp/bible-chapter-verse-count into lp:openlp
Andreas Preikschat has proposed merging lp:~googol/openlp/bible-chapter-verse-count into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~googol/openlp/bible-chapter-verse-count/+merge/100299
Hello,
this improves the speed for receiving the verse/chapter count:
The following figures show the times taken for loading a bible (openlp/plugins/lib/mediaitem:initialiseAdvancedBible):
Trunk:
0:00:01.023467
0:00:00.949889
0:00:00.928590
0:00:00.930481
0:00:01.055914
Branch:
0:00:00.532861
0:00:00.517623
0:00:00.549197
0:00:00.526876
0:00:00.512076
--
https://code.launchpad.net/~googol/openlp/bible-chapter-verse-count/+merge/100299
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/bible-chapter-verse-count into lp:openlp.
=== modified file 'openlp/plugins/bibles/lib/db.py'
--- openlp/plugins/bibles/lib/db.py 2012-03-10 19:12:03 +0000
+++ openlp/plugins/bibles/lib/db.py 2012-03-31 16:28:19 +0000
@@ -25,13 +25,13 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
+import chardet
import logging
-import chardet
import os
import sqlite3
from PyQt4 import QtCore
-from sqlalchemy import Column, ForeignKey, or_, Table, types
+from sqlalchemy import Column, ForeignKey, or_, Table, types, func
from sqlalchemy.orm import class_mapper, mapper, relation
from sqlalchemy.orm.exc import UnmappedClassError
@@ -427,13 +427,11 @@
The book object to get the chapter count for.
"""
log.debug(u'BibleDB.get_chapter_count("%s")', book.name)
- count = self.session.query(Verse.chapter).join(Book)\
- .filter(Book.book_reference_id==book.book_reference_id)\
- .distinct().count()
+ count = self.session.query(func.max(Verse.chapter)).join(Book).filter(
+ Book.book_reference_id==book.book_reference_id).scalar()
if not count:
return 0
- else:
- return count
+ return count
def get_verse_count(self, book_ref_id, chapter):
"""
@@ -446,14 +444,13 @@
The chapter to get the verse count for.
"""
log.debug(u'BibleDB.get_verse_count("%s", "%s")', book_ref_id, chapter)
- count = self.session.query(Verse).join(Book)\
+ count = self.session.query(func.max(Verse.verse)).join(Book)\
.filter(Book.book_reference_id==book_ref_id)\
.filter(Verse.chapter==chapter)\
- .count()
+ .scalar()
if not count:
return 0
- else:
- return count
+ return count
def get_language(self, bible_name=None):
"""
Follow ups