workspaces() ->withCount('socialAccounts') ->get(); return [ 'workspaceCount' => $workspaces->count(), 'socialAccountCount' => (int) $workspaces->sum('social_accounts_count'), 'memberCount' => $this->users()->count(), 'pendingInviteCount' => Invite::where('account_id', $this->id) ->whereNull('accepted_at') ->count(), 'postCount' => $this->cachedPostCount($workspaces->pluck('id')->all()), 'creditsUsed' => BillingCycle::for($this)->usedCredits(), ]; } /** * @return array{monthlyCreditsLimit: int} */ public function featureLimits(): array { return [ 'monthlyCreditsLimit' => BillingCycle::for($this)->creditAllotment(), ]; } /** * The `(int)` cast is load-bearing: Laravel's RedisStore stores numeric * values raw (for atomic INCR) and returns them as strings on read. * * @param array $workspaceIds */ private function cachedPostCount(array $workspaceIds): int { if (empty($workspaceIds)) { return 0; } return (int) Cache::remember( Account::postsCountCacheKey((string) $this->id), self::POST_COUNT_CACHE_TTL, fn () => Post::whereIn('workspace_id', $workspaceIds)->count(), ); } }