shorter db sessions
This commit is contained in:
parent
ebc0b95022
commit
935f8d7f2b
4 changed files with 141 additions and 136 deletions
|
@ -47,8 +47,8 @@ class Downloads(Thread):
|
|||
|
||||
def run(self):
|
||||
time.sleep(2)
|
||||
with db.session():
|
||||
while self._running:
|
||||
with db.session():
|
||||
self.download_next()
|
||||
time.sleep(0.5)
|
||||
|
||||
|
@ -87,9 +87,12 @@ class ScrapeThread(Thread):
|
|||
|
||||
def run(self):
|
||||
time.sleep(2)
|
||||
with db.session():
|
||||
while self._running:
|
||||
wait = False
|
||||
with db.session():
|
||||
if not self.scrape_queue():
|
||||
wait = True
|
||||
if wait:
|
||||
time.sleep(1)
|
||||
|
||||
def join(self):
|
||||
|
|
|
@ -137,7 +137,8 @@ class ReaderHandler(OMLHandler):
|
|||
item.timesaccessed = (item.timesaccessed or 0) + 1
|
||||
item.update_sort()
|
||||
item.save()
|
||||
return serve_static(self, os.path.join(settings.static_path, html), 'text/html')
|
||||
path = os.path.join(settings.static_path, html)
|
||||
return serve_static(self, path, 'text/html')
|
||||
|
||||
class UploadHandler(tornado.web.RequestHandler):
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ def get_icon_app(id, type_, size, callback):
|
|||
from item.models import Item
|
||||
item = Item.get(id)
|
||||
if not item:
|
||||
callback('')
|
||||
data = ''
|
||||
else:
|
||||
if type_ == 'cover' and not item.meta.get('cover'):
|
||||
type_ = 'preview'
|
||||
|
|
|
@ -65,7 +65,6 @@ def add_file(id, f, prefix, from_=None):
|
|||
|
||||
def run_scan():
|
||||
remove_missing()
|
||||
with db.session():
|
||||
prefs = settings.preferences
|
||||
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
|
||||
if not prefix[-1] == '/':
|
||||
|
@ -90,6 +89,7 @@ def run_scan():
|
|||
if not state.tasks.connected:
|
||||
return
|
||||
position += 1
|
||||
with db.session():
|
||||
id = media.get_id(f)
|
||||
file = File.get(id)
|
||||
if not file:
|
||||
|
@ -100,7 +100,6 @@ def run_scan():
|
|||
def run_import(options=None):
|
||||
options = options or {}
|
||||
|
||||
with db.session():
|
||||
logger.debug('run_import')
|
||||
prefs = settings.preferences
|
||||
prefix = os.path.expanduser(options.get('path', prefs['importPath']))
|
||||
|
@ -167,6 +166,7 @@ def run_import(options=None):
|
|||
position += 1
|
||||
if not os.path.exists(f):
|
||||
continue
|
||||
with db.session():
|
||||
id = media.get_id(f)
|
||||
file = File.get(id)
|
||||
if not file:
|
||||
|
@ -195,6 +195,7 @@ def run_import(options=None):
|
|||
if state.activity.get('cancel'):
|
||||
state.activity = {}
|
||||
return
|
||||
with db.session():
|
||||
if listname and listitems:
|
||||
l = List.get(settings.USER_ID, listname)
|
||||
if l:
|
||||
|
|
Loading…
Reference in a new issue