Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
run the label computing code in multithreaded mode - #253
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Jan 2, 2016
1 parent a1f07eb commit 944a7cd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion bauble/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def open(uri, verify=True, show_error_dialogs=False):
poolclass = SingletonThreadPool
new_engine = sa.create_engine(uri, echo=SQLALCHEMY_DEBUG,
implicit_returning=False,
poolclass=poolclass)
poolclass=poolclass, pool_size=16)
# TODO: there is a problem here: the code may cause an exception, but we
# immediately loose the 'new_engine', which should know about the
# encoding used in the exception string.
Expand Down
86 changes: 49 additions & 37 deletions bauble/plugins/plants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,43 +191,55 @@ def update(self):
self.name_tooltip_query = name_tooltip_query

if 'GardenPlugin' in pluginmgr.plugins:
LabelUpdater(self.widgets.splash_nplttot,
"select count(*) from plant").run()
LabelUpdater(self.widgets.splash_npltuse,
"select count(*) from plant where quantity>0").run()
LabelUpdater(self.widgets.splash_nacctot,
"select count(*) from accession").run()
LabelUpdater(self.widgets.splash_naccuse,
"select count(distinct accession.id) "
"from accession "
"join plant on plant.accession_id=accession.id "
"where plant.quantity>0").run()
LabelUpdater(self.widgets.splash_nloctot,
"select count(*) from location").run()
LabelUpdater(self.widgets.splash_nlocuse,
"select count(distinct location.id) "
"from location "
"join plant on plant.location_id=location.id "
"where plant.quantity>0").run()

LabelUpdater(self.widgets.splash_nspcuse,
"select count(distinct species.id) "
"from species join accession "
"on accession.species_id=species.id").run()
LabelUpdater(self.widgets.splash_ngenuse,
"select count(distinct species.genus_id) "
"from species join accession "
"on accession.species_id=species.id").run()
LabelUpdater(self.widgets.splash_nfamuse,
"select count(distinct genus.family_id) from genus "
"join species on species.genus_id=genus.id "
"join accession on accession.species_id=species.id ").run()
LabelUpdater(self.widgets.splash_nspctot,
"select count(*) from species").run()
LabelUpdater(self.widgets.splash_ngentot,
"select count(*) from genus").run()
LabelUpdater(self.widgets.splash_nfamtot,
"select count(*) from family").run()
self.start_thread(
LabelUpdater(self.widgets.splash_nplttot,
"select count(*) from plant"))
self.start_thread(
LabelUpdater(self.widgets.splash_npltuse,
"select count(*) from plant where quantity>0"))
self.start_thread(
LabelUpdater(self.widgets.splash_nacctot,
"select count(*) from accession"))
self.start_thread(
LabelUpdater(self.widgets.splash_naccuse,
"select count(distinct accession.id) "
"from accession "
"join plant on plant.accession_id=accession.id "
"where plant.quantity>0"))
self.start_thread(
LabelUpdater(self.widgets.splash_nloctot,
"select count(*) from location"))
self.start_thread(
LabelUpdater(self.widgets.splash_nlocuse,
"select count(distinct location.id) "
"from location "
"join plant on plant.location_id=location.id "
"where plant.quantity>0"))

self.start_thread(
LabelUpdater(self.widgets.splash_nspcuse,
"select count(distinct species.id) "
"from species join accession "
"on accession.species_id=species.id"))
self.start_thread(
LabelUpdater(self.widgets.splash_ngenuse,
"select count(distinct species.genus_id) "
"from species join accession "
"on accession.species_id=species.id"))
self.start_thread(
LabelUpdater(self.widgets.splash_nfamuse,
"select count(distinct genus.family_id) from genus "
"join species on species.genus_id=genus.id "
"join accession on accession.species_id=species.id "))
self.start_thread(
LabelUpdater(self.widgets.splash_nspctot,
"select count(*) from species"))
self.start_thread(
LabelUpdater(self.widgets.splash_ngentot,
"select count(*) from genus"))
self.start_thread(
LabelUpdater(self.widgets.splash_nfamtot,
"select count(*) from family"))

def on_sqb_clicked(self, btn_no, *args):
try:
Expand Down

0 comments on commit 944a7cd

Please sign in to comment.