Query optimisations.

This commit is contained in:
James Cole
2015-12-26 09:21:45 +01:00
parent 79392ab656
commit 209116e766
3 changed files with 30 additions and 15 deletions

View File

@@ -147,7 +147,11 @@ class ReportQuery implements ReportQueryInterface
// get everything // get everything
$data = $query->get( $data = $query->get(
['transaction_journals.*', 'transaction_types.type', 'ac_from.name as name', 'ac_from.id as account_id', 'ac_from.encrypted as account_encrypted'] ['transaction_journals.*',
'transaction_types.type', 'ac_from.name as name',
't_from.amount as from_amount',
't_to.amount as to_amount',
'ac_from.id as account_id', 'ac_from.encrypted as account_encrypted']
); );
$data->each( $data->each(
@@ -157,15 +161,15 @@ class ReportQuery implements ReportQueryInterface
} }
} }
); );
$data = $data->filter( // $data = $data->filter(
function (TransactionJournal $journal) { // function (TransactionJournal $journal) {
if ($journal->amount != 0) { // if ($journal->amount != 0) {
return $journal; // return $journal;
} // }
//
return null; // return null;
} // }
); // );
return $data; return $data;
} }
@@ -220,7 +224,10 @@ class ReportQuery implements ReportQueryInterface
$query->orderBy('transaction_journals.date'); $query->orderBy('transaction_journals.date');
$data = $query->get( // get everything $data = $query->get( // get everything
['transaction_journals.*', 'transaction_types.type', 'ac_to.name as name', 'ac_to.id as account_id', 'ac_to.encrypted as account_encrypted'] ['transaction_journals.*', 'transaction_types.type',
't_from.amount as from_amount',
't_to.amount as to_amount',
'ac_to.name as name', 'ac_to.id as account_id', 'ac_to.encrypted as account_encrypted']
); );
$data->each( $data->each(

View File

@@ -59,7 +59,6 @@ class JsonController extends Controller
$steps[7]['orphan'] = true; // final in the center again. $steps[7]['orphan'] = true; // final in the center again.
$steps[7]['backdrop'] = true; $steps[7]['backdrop'] = true;
$template = view('json.tour')->render(); $template = view('json.tour')->render();
return Response::json(['steps' => $steps, 'template' => $template]); return Response::json(['steps' => $steps, 'template' => $template]);
} }
@@ -192,7 +191,7 @@ class JsonController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
$accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']); $accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']);
$amount = $reportQuery->incomeInPeriod($start, $end, $accounts)->sum('amount'); $amount = $reportQuery->incomeInPeriod($start, $end, $accounts)->sum('to_amount');
$data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; $data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
$cache->store($data); $cache->store($data);
@@ -221,8 +220,7 @@ class JsonController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
$amount = $reportQuery->expenseInPeriod($start, $end, $accounts)->sum('amount'); $amount = $reportQuery->expenseInPeriod($start, $end, $accounts)->sum('to_amount');
$amount = $amount * -1;
$data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; $data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
$cache->store($data); $cache->store($data);

View File

@@ -9,6 +9,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
@@ -111,6 +112,13 @@ class TagRepository implements TagRepositoryInterface
*/ */
public function get() public function get()
{ {
$cache = new CacheProperties;
$cache->addProperty('tags-list');
if ($cache->has()) {
return $cache->get();
}
/** @var Collection $tags */ /** @var Collection $tags */
$tags = Auth::user()->tags()->get(); $tags = Auth::user()->tags()->get();
$tags = $tags->sortBy( $tags = $tags->sortBy(
@@ -119,6 +127,8 @@ class TagRepository implements TagRepositoryInterface
} }
); );
$cache->store($tags);
return $tags; return $tags;
} }