fix dulicate logic

This commit is contained in:
Isaac Connor 2017-11-26 15:12:35 -05:00
parent 4a884afecb
commit dd3f9492ba
1 changed files with 10 additions and 12 deletions

View File

@ -111,20 +111,18 @@ class Storage {
public function disk_used_space() {
# This isn't a function like this in php, so we have to add up the space used in each event.
if ( ! array_key_exists( 'DiskSpace', $this ) ) {
$used = $this->{'DiskSpace'};
if ( ! $used ) {
if ( $this->{'Type'} == 's3fs' ) {
$used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()) );
$used = 0;
if ( $this->{'Type'} == 's3fs' ) {
$used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()) );
foreach ( Event::find_all( array( 'StorageId'=>$this->Id(), 'DiskSpace'=>null ) ) as $Event ) {
$Event->Storage( $this ); // Prevent further db hit
$used += $Event->DiskSpace();
}
} else {
$path = $this->Path();
$used = disk_total_space( $path ) - disk_free_space( $path );;
foreach ( Event::find_all( array( 'StorageId'=>$this->Id(), 'DiskSpace'=>null ) ) as $Event ) {
$Event->Storage( $this ); // Prevent further db hit
$used += $Event->DiskSpace();
}
} # end if
} else {
$path = $this->Path();
$used = disk_total_space( $path ) - disk_free_space( $path );;
}
$this->{'DiskSpace'} = $used;
}