From 97300ab8a542ba93c381146d7bca8ca9b64685d3 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Thu, 10 Feb 2022 16:45:10 +0000 Subject: [PATCH] Optimised Organisation model to prevent it running 4 extra queries per instance --- .../Interfaces/OrganisationInterface.php | 21 --------------- src/Database/Models/Organisation.php | 27 +------------------ 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/src/Database/Models/Interfaces/OrganisationInterface.php b/src/Database/Models/Interfaces/OrganisationInterface.php index a9760d6..b4da1ca 100644 --- a/src/Database/Models/Interfaces/OrganisationInterface.php +++ b/src/Database/Models/Interfaces/OrganisationInterface.php @@ -18,27 +18,6 @@ use Illuminate\Database\Eloquent\Builder; */ interface OrganisationInterface { - /** - * Get a count of members within this organisation (includes admins). - * - * @return integer The number of members within the organisation. - */ - public function getMemberCountAttribute(); - - /** - * Get a count of administrators within this organisation. - * - * @return integer The number of admins within the organisation. - */ - public function getAdminCountAttribute(); - - /** - * Get a count of members within this organisation (excludes admins). - * - * @return integer The number of members within the organisation. - */ - public function getTotalMemberCountAttribute(); - /** * Delete this organisation from the database, along with any linked objects. * diff --git a/src/Database/Models/Organisation.php b/src/Database/Models/Organisation.php index e3cb647..7b22be0 100644 --- a/src/Database/Models/Organisation.php +++ b/src/Database/Models/Organisation.php @@ -65,8 +65,7 @@ class Organisation extends Model implements OrganisationInterface * @var array */ protected $appends = [ - 'member_count', - 'admin_count' + ]; /** @@ -84,30 +83,6 @@ class Organisation extends Model implements OrganisationInterface public $timestamps = true; - /** - * Get a count of members within this organisation (includes admins). - */ - public function getMemberCountAttribute() - { - return $this->members()->count(); - } - - /** - * Get a count of administrators within this organisation. - */ - public function getAdminCountAttribute() - { - return $this->administrators()->count(); - } - - /** - * Get a count of members within this organisation (excludes admins). - */ - public function getTotalMemberCountAttribute() - { - return $this->members()->count() + $this->administrators()->count(); - } - /** * Get a list of members within this organisation. */