diff sat/memory/sqlite.py @ 3523:30779935c0aa

core (memory, sqlite): new `fileGetUsedSpace` method
author Goffi <goffi@goffi.org>
date Wed, 05 May 2021 15:37:21 +0200
parents be6d91572633
children 67aebefb44fc
line wrap: on
line diff
--- a/sat/memory/sqlite.py	Wed May 05 12:58:11 2021 +0200
+++ b/sat/memory/sqlite.py	Wed May 05 15:37:21 2021 +0200
@@ -986,6 +986,15 @@
         d.addErrback(lambda failure: log.error(_("Can't save file metadata for [{profile}]: {reason}".format(profile=client.profile, reason=failure))))
         return d
 
+    async def fileGetUsedSpace(self, client, owner):
+        """Get space used by owner of file"""
+        query = "SELECT SUM(size) FROM files WHERE owner=? AND type='file' AND profile_id=?"
+        ret = await self.dbpool.runQuery(
+            query,
+            (owner.userhost(), self.profiles[client.profile])
+        )
+        return ret[0][0]
+
     def _fileUpdate(self, cursor, file_id, column, update_cb):
         query = 'SELECT {column} FROM files where id=?'.format(column=column)
         for i in range(5):