[DB][Attachments] Use count function rathar than fetch and count, rename to refCount, rather than countDepencies

This commit is contained in:
2021-08-10 08:04:03 +00:00
parent 8880405dee
commit 39006fb6b5
3 changed files with 8 additions and 15 deletions

View File

@@ -246,28 +246,22 @@ class Attachment extends Entity
const URLHASH_ALGO = 'sha256';
const FILEHASH_ALGO = 'sha256';
/**
*
* Warning: Underlying DB::findBy doesn't respect remove persistence
* @return int
*/
public function countDependencies(): int
public function refCount(): int
{
$attachment_id = $this->getId();
$notes = DB::findBy('attachment_to_note', ['attachment_id' => $attachment_id]);
$dependencies = count($notes);
Event::handle('AttachmentCountDependencies', [$attachment_id, &$dependencies]);
$dependencies = DB::count('attachment_to_note', ['attachment_id' => $attachment_id]);
Event::handle('AttachmentRefCount', [$attachment_id, &$dependencies]);
return $dependencies;
}
/**
* @depends Attachment->refCount()
*
* @depends Attachment->countDependencies()
* @return bool
*/
public function isSafeDelete(): bool
{
return $this->countDependencies() === 0;
return $this->refCount() === 0;
}
/**