Skip to content

Commit

Permalink
GetTotal size also return optional sum of optional file sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Oct 4, 2017
1 parent aa9e8b0 commit 96ceb25
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Content/ContentDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def setContent(self, site, inner_path, content, size=0):
"size": size,
"size_files": sum([val["size"] for key, val in content.get("files", {}).iteritems()]),
"size_files_optional": sum([val["size"] for key, val in content.get("files_optional", {}).iteritems()]),
"modified": int(content["modified"])
"modified": int(content.get("modified", 0))
}, {
"site_id": self.site_ids.get(site.address, 0),
"inner_path": inner_path
Expand All @@ -116,15 +116,15 @@ def getTotalSize(self, site, ignore=None):
params = {"site_id": self.site_ids.get(site.address, 0)}
if ignore:
params["not__inner_path"] = ignore
res = self.execute("SELECT SUM(size) + SUM(size_files) AS size FROM content WHERE ?", params)
return res.fetchone()["size"]
res = self.execute("SELECT SUM(size) + SUM(size_files) AS size, SUM(size_files_optional) AS size_optional FROM content WHERE ?", params)
row = dict(res.fetchone())

def getOptionalSize(self, site):
res = self.execute(
"SELECT SUM(size_files_optional) AS size FROM content WHERE ?",
{"site_id": self.site_ids.get(site.address, 0)}
)
return res.fetchone()["size"]
if not row["size"]:
row["size"] = 0
if not row["size_optional"]:
row["size_optional"] = 0

return row["size"], row["size_optional"]

def listModified(self, site, since):
res = self.execute(
Expand Down

0 comments on commit 96ceb25

Please sign in to comment.