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