Rev3155, Avoid UI hang during db rebuild
This commit is contained in:
parent
6b92d011d2
commit
90ff9ac7fb
2 changed files with 9 additions and 3 deletions
|
@ -10,7 +10,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.6.0"
|
self.version = "0.6.0"
|
||||||
self.rev = 3153
|
self.rev = 3155
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.config_file = "zeronet.conf"
|
self.config_file = "zeronet.conf"
|
||||||
|
|
|
@ -83,6 +83,7 @@ class SiteStorage(object):
|
||||||
|
|
||||||
# Return possible db files for the site
|
# Return possible db files for the site
|
||||||
def getDbFiles(self):
|
def getDbFiles(self):
|
||||||
|
found = 0
|
||||||
for content_inner_path, content in self.site.content_manager.contents.iteritems():
|
for content_inner_path, content in self.site.content_manager.contents.iteritems():
|
||||||
# content.json file itself
|
# content.json file itself
|
||||||
if self.isFile(content_inner_path):
|
if self.isFile(content_inner_path):
|
||||||
|
@ -100,6 +101,9 @@ class SiteStorage(object):
|
||||||
yield file_inner_path, self.getPath(file_inner_path)
|
yield file_inner_path, self.getPath(file_inner_path)
|
||||||
else:
|
else:
|
||||||
self.log.error("[MISSING] %s" % file_inner_path)
|
self.log.error("[MISSING] %s" % file_inner_path)
|
||||||
|
found += 1
|
||||||
|
if found % 100 == 0:
|
||||||
|
time.sleep(0.000001) # Context switch to avoid UI block
|
||||||
|
|
||||||
# Rebuild sql cache
|
# Rebuild sql cache
|
||||||
def rebuildDb(self, delete_db=True):
|
def rebuildDb(self, delete_db=True):
|
||||||
|
@ -122,13 +126,14 @@ class SiteStorage(object):
|
||||||
self.openDb(check=False)
|
self.openDb(check=False)
|
||||||
self.log.info("Creating tables...")
|
self.log.info("Creating tables...")
|
||||||
self.db.checkTables()
|
self.db.checkTables()
|
||||||
self.log.info("Importing data...")
|
|
||||||
cur = self.db.getCursor()
|
cur = self.db.getCursor()
|
||||||
cur.execute("BEGIN")
|
cur.execute("BEGIN")
|
||||||
cur.logging = False
|
cur.logging = False
|
||||||
found = 0
|
found = 0
|
||||||
s = time.time()
|
s = time.time()
|
||||||
|
self.log.info("Getting db files...")
|
||||||
db_files = list(self.getDbFiles())
|
db_files = list(self.getDbFiles())
|
||||||
|
self.log.info("Importing data...")
|
||||||
try:
|
try:
|
||||||
if len(db_files) > 100:
|
if len(db_files) > 100:
|
||||||
self.site.messageWebsocket(_["Database rebuilding...<br>Imported {0} of {1} files..."].format("0000", len(db_files)), "rebuild", 0)
|
self.site.messageWebsocket(_["Database rebuilding...<br>Imported {0} of {1} files..."].format("0000", len(db_files)), "rebuild", 0)
|
||||||
|
@ -144,6 +149,7 @@ class SiteStorage(object):
|
||||||
"rebuild",
|
"rebuild",
|
||||||
int(float(found) / len(db_files) * 100)
|
int(float(found) / len(db_files) * 100)
|
||||||
)
|
)
|
||||||
|
time.sleep(0.000001) # Context switch to avoid UI block
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
cur.execute("END")
|
cur.execute("END")
|
||||||
|
@ -471,7 +477,7 @@ class SiteStorage(object):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
break
|
break
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
self.log.error("Error removing %s: %s, try #%s" % (path, err, retry))
|
self.log.error(u"Error removing %s: %s, try #%s" % (inner_path, err, retry))
|
||||||
time.sleep(float(retry) / 10)
|
time.sleep(float(retry) / 10)
|
||||||
self.onUpdated(inner_path, False)
|
self.onUpdated(inner_path, False)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue