mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Cache boxes.
This commit is contained in:
parent
616c849b1f
commit
be17e4481e
@ -1,6 +1,7 @@
|
|||||||
<?php namespace FireflyIII\Http\Controllers;
|
<?php namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
use Amount;
|
use Amount;
|
||||||
|
use Cache;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
@ -10,7 +11,9 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
|
use FireflyIII\Support\ChartProperties;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
use Steam;
|
use Steam;
|
||||||
@ -33,10 +36,24 @@ class JsonController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function boxBillsPaid(BillRepositoryInterface $repository, AccountRepositoryInterface $accountRepository)
|
public function boxBillsPaid(BillRepositoryInterface $repository, AccountRepositoryInterface $accountRepository)
|
||||||
{
|
{
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
|
// works for json too!
|
||||||
|
$prop = new ChartProperties;
|
||||||
|
$prop->addProperty($start);
|
||||||
|
$prop->addProperty($end);
|
||||||
|
$prop->addProperty('box-bills-paid');
|
||||||
|
$md5 = $prop->md5();
|
||||||
|
if (Cache::has($md5)) {
|
||||||
|
Log::debug('Successfully returned cached box bills-paid [' . $md5 . ']');
|
||||||
|
|
||||||
|
return Response::json(Cache::get($md5));
|
||||||
|
}
|
||||||
|
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
|
|
||||||
|
|
||||||
// these two functions are the same as the chart
|
// these two functions are the same as the chart
|
||||||
$bills = $repository->getActiveBills();
|
$bills = $repository->getActiveBills();
|
||||||
|
|
||||||
@ -60,8 +77,10 @@ class JsonController extends Controller
|
|||||||
$amount += $accountRepository->getTransfersInRange($creditCard, $start, $end)->sum('amount');
|
$amount += $accountRepository->getTransfersInRange($creditCard, $start, $end)->sum('amount');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
||||||
|
Cache::forever($md5, $data);
|
||||||
|
|
||||||
return Response::json(['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,6 +94,19 @@ class JsonController extends Controller
|
|||||||
$amount = 0;
|
$amount = 0;
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
|
// works for json too!
|
||||||
|
$prop = new ChartProperties;
|
||||||
|
$prop->addProperty($start);
|
||||||
|
$prop->addProperty($end);
|
||||||
|
$prop->addProperty('box-bills-unpaid');
|
||||||
|
$md5 = $prop->md5();
|
||||||
|
if (Cache::has($md5)) {
|
||||||
|
Log::debug('Successfully returned cached box bills-unpaid [' . $md5 . ']');
|
||||||
|
|
||||||
|
return Response::json(Cache::get($md5));
|
||||||
|
}
|
||||||
|
|
||||||
$bills = $repository->getActiveBills();
|
$bills = $repository->getActiveBills();
|
||||||
$unpaid = new Collection; // bills
|
$unpaid = new Collection; // bills
|
||||||
|
|
||||||
@ -109,7 +141,10 @@ class JsonController extends Controller
|
|||||||
$amount += $current;
|
$amount += $current;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response::json(['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]);
|
$data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
||||||
|
Cache::forever($md5, $data);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,11 +154,28 @@ class JsonController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function boxIn(ReportQueryInterface $reportQuery)
|
public function boxIn(ReportQueryInterface $reportQuery)
|
||||||
{
|
{
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
|
// works for json too!
|
||||||
|
$prop = new ChartProperties;
|
||||||
|
$prop->addProperty($start);
|
||||||
|
$prop->addProperty($end);
|
||||||
|
$prop->addProperty('box-in');
|
||||||
|
$md5 = $prop->md5();
|
||||||
|
if (Cache::has($md5)) {
|
||||||
|
Log::debug('Successfully returned cached box in [' . $md5 . ']');
|
||||||
|
|
||||||
|
return Response::json(Cache::get($md5));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount');
|
$amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount');
|
||||||
|
|
||||||
return Response::json(['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]);
|
$data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
||||||
|
Cache::forever($md5, $data);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,11 +185,28 @@ class JsonController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function boxOut(ReportQueryInterface $reportQuery)
|
public function boxOut(ReportQueryInterface $reportQuery)
|
||||||
{
|
{
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
|
|
||||||
|
// works for json too!
|
||||||
|
$prop = new ChartProperties;
|
||||||
|
$prop->addProperty($start);
|
||||||
|
$prop->addProperty($end);
|
||||||
|
$prop->addProperty('box-out');
|
||||||
|
$md5 = $prop->md5();
|
||||||
|
if (Cache::has($md5)) {
|
||||||
|
Log::debug('Successfully returned cached box out [' . $md5 . ']');
|
||||||
|
|
||||||
|
return Response::json(Cache::get($md5));
|
||||||
|
}
|
||||||
|
|
||||||
$amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount');
|
$amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount');
|
||||||
|
|
||||||
return Response::json(['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]);
|
$data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
|
||||||
|
Cache::forever($md5, $data);
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user