From 9f7c6c2d0c5ef41daf75d7bec481225b3d7bf971 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 25 Dec 2015 17:11:55 +0100 Subject: [PATCH] Extra cache. --- app/Repositories/Account/AccountRepository.php | 17 +++++++++++++---- app/Repositories/Journal/JournalRepository.php | 12 +++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 2668c85938..cdadf440c7 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -41,7 +41,16 @@ class AccountRepository implements AccountRepositoryInterface */ public function countAccounts(array $types) { - return Auth::user()->accounts()->accountTypeIn($types)->count(); + $cache = new CacheProperties; + $cache->addProperty('user-count-accounts'); + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + + $count = Auth::user()->accounts()->accountTypeIn($types)->count(); + $cache->store($count); + + return $count; } /** @@ -123,8 +132,7 @@ class AccountRepository implements AccountRepositoryInterface public function getFrontpageAccounts(Preference $preference) { $cache = new CacheProperties(); - $cache->addProperty($preference->data); - $cache->addProperty('frontPageaccounts'); + $cache->addProperty('user-frontpage-accounts'); if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore } @@ -229,7 +237,7 @@ class AccountRepository implements AccountRepositoryInterface $cache = new CacheProperties; $cache->addProperty($ids); - $cache->addProperty('piggyAccounts'); + $cache->addProperty('user-piggy-bank-accounts'); if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore } @@ -648,6 +656,7 @@ class AccountRepository implements AccountRepositoryInterface /** * @deprecated + * * @param $accountId * * @return Account diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 3fd766b1a5..b86a6704f3 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -13,6 +13,7 @@ use FireflyIII\Models\Tag; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; +use FireflyIII\Support\CacheProperties; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Log; @@ -44,7 +45,16 @@ class JournalRepository implements JournalRepositoryInterface */ public function first() { - return Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']); + $cache = new CacheProperties; + $cache->addProperty('user-first-journal'); + if ($cache->has()) { + return $cache->get(); // @codeCoverageIgnore + } + + $entry = Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']); + $cache->store($entry); + + return $entry; } /**