diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-02-14 08:24:18 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-02-14 08:24:18 +0900 |
| commit | 434bced6f4aadb8b3291e32f87c4f55454e029d4 (patch) | |
| tree | c3007e2f346467c913f38196ce248c7ed69e48b8 /src/api/common | |
| parent | [Test] Better /drive test (diff) | |
| download | sharkey-434bced6f4aadb8b3291e32f87c4f55454e029d4.tar.gz sharkey-434bced6f4aadb8b3291e32f87c4f55454e029d4.tar.bz2 sharkey-434bced6f4aadb8b3291e32f87c4f55454e029d4.zip | |
#160
Diffstat (limited to 'src/api/common')
| -rw-r--r-- | src/api/common/add-file-to-drive.ts | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index bbff93ac7a..714eeb520d 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -79,17 +79,20 @@ export default ( } } - // Fetch all files to calculate drive usage - const files = await DriveFile - .find({ user_id: user._id }, { - fields: { - datasize: true, - _id: false - } - }); - - // Calculate drive usage (in byte) - const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0); + // Calculate drive usage + const usage = ((await DriveFile + .aggregate([ + { $match: { user_id: user._id } }, + { $project: { + datasize: true + }}, + { $group: { + _id: null, + usage: { $sum: '$datasize' } + }} + ]))[0] || { + usage: 0 + }).usage; log(`drive usage is ${usage}`); |