use SQL to calculate storage used

This commit is contained in:
printempw 2016-08-24 22:43:30 +08:00
parent 98505984e1
commit cece50e1a3

View File

@ -165,12 +165,10 @@ class User
if (is_null($this->storage_used)) {
$this->storage_used = 0;
// recalculate
foreach (Texture::where('uploader', $this->uid)->get() as $t) {
$this->storage_used += $t->size;
}
$prefix = \Config::getDbConfig()['prefix'];
$sql = "SELECT SUM(`size`) AS total_size FROM `{$prefix}textures` WHERE uploader = {$this->uid}";
$this->storage_used = \DB::fetchArray($sql)['total_size'];
}
return $this->storage_used;
}