summaryrefslogtreecommitdiffstats
path: root/module/database
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2011-12-08 18:40:55 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2011-12-08 18:40:55 +0100
commit12e0357c2fb7cf9aabb4744a8fed49426c21ba68 (patch)
treee1c9c3ffbe01aa5a346a3f1cb8dd5b894620f1cd /module/database
parentfixed deprecation warnings (diff)
downloadpyload-12e0357c2fb7cf9aabb4744a8fed49426c21ba68.tar.xz
fixed order consistence, fixed typo in json_app
Diffstat (limited to 'module/database')
-rw-r--r--module/database/FileDatabase.py59
1 files changed, 52 insertions, 7 deletions
diff --git a/module/database/FileDatabase.py b/module/database/FileDatabase.py
index 1df8998b0..6c7bfe1de 100644
--- a/module/database/FileDatabase.py
+++ b/module/database/FileDatabase.py
@@ -169,8 +169,10 @@ class FileHandler:
self.core.pullManager.addEvent(e)
self.core.hookManager.dispatchEvent("packageDeleted", id)
- if id in self.packageCache:
- del self.packageCache[id]
+ #if id in self.packageCache:
+ # del self.packageCache[id]
+
+ self.packageCache = {} # force order refresh
#----------------------------------------------------------------------
@lock
@@ -435,6 +437,8 @@ class FileHandler:
pack = self.getPackage(id)
e = InsertEvent("pack", id, pack.order, "collector" if not pack.queue else "queue")
self.core.pullManager.addEvent(e)
+
+ self.packageCache = {} # force order refresh
@lock
@change
@@ -457,10 +461,12 @@ class FileHandler:
p.order = position
self.db.commit()
-
- e = ReloadAllEvent("collector" if not p.queue else "queue")
+
+ e = InsertEvent("pack", id, pack.order, "collector" if not pack.queue else "queue")
self.core.pullManager.addEvent(e)
+ self.packageCache = {} # force order refresh
+
@lock
@change
def reorderFile(self, id, position):
@@ -486,10 +492,11 @@ class FileHandler:
self.cache[id].order = position
self.db.commit()
-
- e = ReloadAllEvent("collector" if not self.getPackage(f["package"]).queue else "queue")
-
+
+ e = InsertEvent("file", id, f["order"], "collector" if not self.getPackage(f["package"]).queue else "queue")
self.core.pullManager.addEvent(e)
+
+ self.cache = {} # force order refresh
@change
def updateFileInfo(self, data, pid):
@@ -541,6 +548,9 @@ class FileHandler:
deleted.append(id)
self.deletePackage(int(id))
+
+ self.packageCache = {} # force order refresh
+
return deleted
@lock
@@ -548,6 +558,11 @@ class FileHandler:
def restartFailed(self):
""" restart all failed links """
self.db.restartFailed()
+
+ @lock
+ @change
+ def fixPackageOrder(self, queue=0):
+ self.db.fixPackageOrder(queue)
class FileMethods():
@style.queue
@@ -849,12 +864,42 @@ class FileMethods():
@style.queue
def deleteFinished(self):
self.c.execute("DELETE FROM links WHERE status IN (0,4)")
+ self.c.execute("DELETE FROM links WHERE status IN (0,4)")
self.c.execute("DELETE FROM packages WHERE NOT EXISTS(SELECT 1 FROM links WHERE packages.id=links.package)")
@style.queue
def restartFailed(self):
self.c.execute("UPDATE links SET status=3,error='' WHERE status IN (8, 9)")
+
+
+ @style.queue
+ def fixPackageOrder(self, queue=0):
+ found = 0
+ order = 0
+ i = 0
+ self.c.execute("SELECT count(*) FROM packages WHERE queue = ?", (queue, ))
+ count = self.c.fetchone()[0]
+ if count == 0:
+ return
+ while order < count:
+ self.c.execute("SELECT id FROM packages WHERE packageorder = ? AND queue = ?", (i, queue))
+ all = self.c.fetchall()
+ if len(all) == 0:
+ i += 1
+ elif len(all) == 1:
+ self.c.execute("UPDATE packages SET packageorder=? WHERE id = ?", (order, all[0][0]))
+ order += 1
+ i += 1
+ elif len(all) > 1:
+ self.c.execute("UPDATE packages SET packageorder=? WHERE id = ?", (order, all[0][0]))
+ order += 1
+ i += len(all)
+ del all[0]
+ self.c.execute("UPDATE packages SET packageorder=packageorder+? WHERE packageorder >= ? AND queue=?", (len(all), order, queue))
+ for r in all:
+ self.c.execute("UPDATE packages SET packageorder=? WHERE id = ?", order, r[0])
+ order += 1
@style.queue