mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add caching to various queries and lists.
This commit is contained in:
parent
3ca1207231
commit
79392ab656
@ -244,7 +244,6 @@ class JsonController extends Controller
|
||||
foreach ($list as $entry) {
|
||||
$return[] = $entry->name;
|
||||
}
|
||||
sort($return);
|
||||
|
||||
return Response::json($return);
|
||||
}
|
||||
|
@ -78,6 +78,14 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getAccounts(array $types)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('get-accounts');
|
||||
$cache->addProperty($types);
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
/** @var Collection $result */
|
||||
$result = Auth::user()->accounts()->with(
|
||||
['accountmeta' => function (HasMany $query) {
|
||||
@ -91,6 +99,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
);
|
||||
|
||||
$cache->store($result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -120,8 +130,18 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getFirstTransaction(TransactionJournal $journal, Account $account)
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('first-transaction');
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty($account->id);
|
||||
|
||||
return $journal->transactions()->where('account_id', $account->id)->first();
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
$transaction = $journal->transactions()->where('account_id', $account->id)->first();
|
||||
$cache->store($transaction);
|
||||
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -383,12 +403,23 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function openingBalanceTransaction(Account $account)
|
||||
{
|
||||
return TransactionJournal
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty('opening-balance-journal');
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
||||
$journal = TransactionJournal
|
||||
::orderBy('transaction_journals.date', 'ASC')
|
||||
->accountIs($account)
|
||||
->transactionTypes([TransactionType::OPENING_BALANCE])
|
||||
->orderBy('created_at', 'ASC')
|
||||
->first(['transaction_journals.*']);
|
||||
$cache->store($journal);
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,6 +50,13 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('category-list');
|
||||
|
||||
if($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = Auth::user()->categories()->orderBy('name', 'ASC')->get();
|
||||
$set = $set->sortBy(
|
||||
@ -58,6 +65,8 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
|
||||
}
|
||||
);
|
||||
|
||||
$cache->store($set);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user