mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-03-07 15:16:40 +08:00
use Query Builder to get storage size used by user
This commit is contained in:
parent
118d8cc649
commit
3569c43fb2
@ -39,6 +39,13 @@ class User extends Model
|
|||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
protected $fillable = ['email', 'nickname', 'permission'];
|
protected $fillable = ['email', 'nickname', 'permission'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage size used by user in KiB.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $storageUsed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if user is admin.
|
* Check if user is admin.
|
||||||
*
|
*
|
||||||
@ -253,14 +260,18 @@ class User extends Model
|
|||||||
*/
|
*/
|
||||||
public function getStorageUsed()
|
public function getStorageUsed()
|
||||||
{
|
{
|
||||||
if (is_null($this->storage_used)) {
|
if (is_null($this->storageUsed)) {
|
||||||
$this->storage_used = 0;
|
$this->storageUsed = 0;
|
||||||
// recalculate
|
|
||||||
$sql = "SELECT SUM(`size`) AS total_size FROM `{table}` WHERE uploader = {$this->uid}";
|
$result = DB::table('textures')
|
||||||
$result = \Database::table('textures')->fetchArray($sql)['total_size'];
|
->select(DB::raw("SUM(size) AS total_size"))
|
||||||
$this->storage_used = $result ?: 0;
|
->where('uploader', $this->uid)
|
||||||
|
->first()->total_size;
|
||||||
|
|
||||||
|
$this->storageUsed = $result ?: 0;
|
||||||
}
|
}
|
||||||
return $this->storage_used;
|
|
||||||
|
return $this->storageUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user