Skip to content

Firefly III: a personal finances manager

Some experiments with a cache control thing. [skip ci]

James Cole71947c097f85
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index bddabbd04b..ffe7354574 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -86,6 +86,7 @@ class AccountController extends Controller
$repository->destroy($account);
Session::flash('success', trans('firefly.' . $typeName . '_deleted', ['name' => $name]));
+ Preferences::mark();
return Redirect::to(Session::get('accounts.delete.url'));
}
@@ -206,6 +207,7 @@ class AccountController extends Controller
$account = $repository->store($accountData);
Session::flash('success', 'New account "' . $account->name . '" stored!');
+ Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
@@ -246,6 +248,7 @@ class AccountController extends Controller
$repository->update($account, $accountData);
Session::flash('success', 'Account "' . $account->name . '" updated.');
+ Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index 80bc497336..6d96298615 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -6,6 +6,7 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Input;
+use Preferences;
use Redirect;
use Session;
use URL;
@@ -75,6 +76,7 @@ class BillController extends Controller
$repository->destroy($bill);
Session::flash('success', 'The bill was deleted.');
+ Preferences::mark();
return Redirect::to(Session::get('bills.delete.url'));
@@ -141,6 +143,7 @@ class BillController extends Controller
Session::flash('success', 'Rescanned everything.');
+ Preferences::mark();
return Redirect::to(URL::previous());
}
@@ -172,6 +175,7 @@ class BillController extends Controller
$billData = $request->getBillData();
$bill = $repository->store($billData);
Session::flash('success', 'Bill "' . e($bill->name) . '" stored.');
+ Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
@@ -198,6 +202,7 @@ class BillController extends Controller
$bill = $repository->update($bill, $billData);
Session::flash('success', 'Bill "' . e($bill->name) . '" updated.');
+ Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index b4d0cca20e..95d43d1535 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -49,6 +49,7 @@ class BudgetController extends Controller
if ($amount == 0) {
$limitRepetition = null;
}
+ Preferences::mark();
return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]);
@@ -102,6 +103,7 @@ class BudgetController extends Controller
Session::flash('success', 'The budget "' . e($name) . '" was deleted.');
+ Preferences::mark();
return Redirect::to(Session::get('budgets.delete.url'));
@@ -196,6 +198,7 @@ class BudgetController extends Controller
$date = Session::get('start', Carbon::now()->startOfMonth())->format('FY');
Preferences::set('budgetIncomeTotal' . $date, intval(Input::get('amount')));
+ Preferences::mark();
return Redirect::route('budgets.index');
}
@@ -242,6 +245,7 @@ class BudgetController extends Controller
$budget = $repository->store($budgetData);
Session::flash('success', 'New budget "' . $budget->name . '" stored!');
+ Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
@@ -272,6 +276,7 @@ class BudgetController extends Controller
$repository->update($budget, $budgetData);
Session::flash('success', 'Budget "' . $budget->name . '" updated.');
+ Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index 92f027ab26..6de44dbba9 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -7,6 +7,7 @@ use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Input;
+use Preferences;
use Redirect;
use Session;
use URL;
@@ -77,6 +78,7 @@ class CategoryController extends Controller
$repository->destroy($category);
Session::flash('success', 'The category "' . e($name) . '" was deleted.');
+ Preferences::mark();
return Redirect::to(Session::get('categories.delete.url'));
}
@@ -168,6 +170,7 @@ class CategoryController extends Controller
$category = $repository->store($categoryData);
Session::flash('success', 'New category "' . $category->name . '" stored!');
+ Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
Session::put('categories.create.fromStore', true);
@@ -195,6 +198,7 @@ class CategoryController extends Controller
$repository->update($category, $categoryData);
Session::flash('success', 'Category "' . $category->name . '" updated.');
+ Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
Session::put('categories.edit.fromUpdate', true);
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index 204f99c03f..e7f4d5b7fc 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -2,6 +2,7 @@
namespace FireflyIII\Http\Controllers\Chart;
+use Auth;
use Cache;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
@@ -10,11 +11,11 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\ChartProperties;
use Grumpydictator\Gchart\GChart;
use Illuminate\Support\Collection;
+use Log;
use Preferences;
use Response;
use Session;
use Steam;
-use Auth;
/**
* Class AccountController
@@ -40,6 +41,23 @@ class AccountController extends Controller
$start = new Carbon($year . '-' . $month . '-01');
$end = clone $start;
$end->endOfMonth();
+
+ // chart properties for cache:
+ $chartProperties = new ChartProperties();
+ $chartProperties->addProperty($start);
+ $chartProperties->addProperty($end);
+ $chartProperties->addProperty('all');
+ $chartProperties->addProperty('accounts');
+ $md5 = $chartProperties->md5();
+
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
+
$chart->addColumn(trans('firefly.dayOfMonth'), 'date');
/** @var Collection $accounts */
@@ -76,7 +94,10 @@ class AccountController extends Controller
}
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+
+ return Response::json($data);
}
/**
@@ -98,22 +119,17 @@ class AccountController extends Controller
// chart properties for cache:
$chartProperties = new ChartProperties();
- $chartProperties->addProperty(Auth::user()->id);
- $chartProperties->addProperty($frontPage);
$chartProperties->addProperty($start);
$chartProperties->addProperty($end);
$chartProperties->addProperty('frontpage');
$chartProperties->addProperty('accounts');
-
- /** @var Account $account */
- foreach($accounts as $account) {
- $chartProperties->addProperty($repository->getLastActivity($account));
- }
-
$md5 = $chartProperties->md5();
+
if (Cache::has($md5)) {
- return Cache::get($md5);
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
}
@@ -165,6 +181,24 @@ class AccountController extends Controller
$current = clone $start;
$today = new Carbon;
+ // chart properties for cache:
+ $chartProperties = new ChartProperties();
+ $chartProperties->addProperty($start);
+ $chartProperties->addProperty($end);
+ $chartProperties->addProperty('frontpage');
+ $chartProperties->addProperty('single');
+ $chartProperties->addProperty($account->id);
+ $md5 = $chartProperties->md5();
+
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
+
+
while ($end >= $current) {
$certain = $current < $today;
$chart->addRow(clone $current, Steam::balance($account, $current), $certain);
@@ -174,6 +208,9 @@ class AccountController extends Controller
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+
+ return Response::json($data);
}
}
diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php
index 9ba00ee2fc..569aee84d5 100644
--- a/app/Http/Controllers/Chart/BillController.php
+++ b/app/Http/Controllers/Chart/BillController.php
@@ -8,12 +8,14 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
+use FireflyIII\Support\ChartProperties;
use Grumpydictator\Gchart\GChart;
use Illuminate\Support\Collection;
use Response;
use Session;
use Steam;
-
+use Cache;
+use Log;
/**
* Class BillController
*
@@ -38,6 +40,18 @@ class BillController extends Controller
$chart->addColumn(trans('firefly.minAmount'), 'number');
$chart->addColumn(trans('firefly.billEntry'), 'number');
+ $chartProperties = new ChartProperties;
+ $chartProperties->addProperty('single');
+ $chartProperties->addProperty('bill');
+ $chartProperties->addProperty($bill->id);
+ $md5 = $chartProperties->md5();
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
// get first transaction or today for start:
$results = $repository->getJournals($bill);
/** @var TransactionJournal $result */
@@ -47,8 +61,10 @@ class BillController extends Controller
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+ return Response::json($data);
}
/**
@@ -68,6 +84,22 @@ class BillController extends Controller
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
+
+
+ // chart properties for cache:
+ $chartProperties = new ChartProperties();
+ $chartProperties->addProperty($start);
+ $chartProperties->addProperty($end);
+ $chartProperties->addProperty('bills');
+ $chartProperties->addProperty('frontpage');
+ $md5 = $chartProperties->md5();
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
$bills = $repository->getActiveBills();
$paid = new Collection; // journals.
$unpaid = new Collection; // bills
@@ -133,8 +165,12 @@ class BillController extends Controller
$chart->addRow(trans('firefly.unpaid') . ': ' . join(', ', $unpaidDescriptions), $unpaidAmount);
$chart->addRow(trans('firefly.paid') . ': ' . join(', ', $paidDescriptions), $paidAmount);
+
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+
+ return Response::json($data);
}
}
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 81f7229603..649c2be783 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -2,7 +2,7 @@
namespace FireflyIII\Http\Controllers\Chart;
-use Auth;
+use Cache;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Budget;
@@ -11,6 +11,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\ChartProperties;
use Grumpydictator\Gchart\GChart;
use Illuminate\Support\Collection;
+use Log;
use Navigation;
use Preferences;
use Response;
@@ -43,6 +44,21 @@ class BudgetController extends Controller
$final->addYears(2);
$last = Navigation::endOfX($last, $range, $final);
+ // chart properties for cache:
+ $chartProperties = new ChartProperties();
+ $chartProperties->addProperty($first);
+ $chartProperties->addProperty($last);
+ $chartProperties->addProperty('budget');
+ $chartProperties->addProperty('budget');
+ $md5 = $chartProperties->md5();
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
+
while ($first < $last) {
$end = Navigation::addPeriod($first, $range, 0);
@@ -55,7 +71,10 @@ class BudgetController extends Controller
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+
+ return Response::json($data);
}
/**
@@ -73,6 +92,22 @@ class BudgetController extends Controller
$start = clone $repetition->startdate;
$end = $repetition->enddate;
+ // chart properties for cache:
+ $chartProperties = new ChartProperties();
+ $chartProperties->addProperty($start);
+ $chartProperties->addProperty($end);
+ $chartProperties->addProperty('budget');
+ $chartProperties->addProperty('limit');
+ $chartProperties->addProperty($budget->id);
+ $chartProperties->addProperty($repetition->id);
+ $md5 = $chartProperties->md5();
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
$chart->addColumn(trans('firefly.day'), 'date');
$chart->addColumn(trans('firefly.left'), 'number');
@@ -90,7 +125,10 @@ class BudgetController extends Controller
}
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+
+ return Response::json($data);
}
@@ -114,6 +152,20 @@ class BudgetController extends Controller
$end = Session::get('end', Carbon::now()->endOfMonth());
$allEntries = new Collection;
+ // chart properties for cache:
+ $chartProperties = new ChartProperties();
+ $chartProperties->addProperty($start);
+ $chartProperties->addProperty($end);
+ $chartProperties->addProperty('budget');
+ $chartProperties->addProperty('all');
+ $md5 = $chartProperties->md5();
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
/** @var Budget $budget */
foreach ($budgets as $budget) {
@@ -131,9 +183,9 @@ class BudgetController extends Controller
$overspent = $expenses > floatval($repetition->amount) ? $expenses - floatval($repetition->amount) : 0;
$allEntries->push(
[$budget->name . ' (' . $repetition->startdate->formatLocalized($this->monthAndDayFormat) . ')',
- $left,
- $spent,
- $overspent
+ $left,
+ $spent,
+ $overspent
]
);
}
@@ -150,7 +202,10 @@ class BudgetController extends Controller
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+
+ return Response::json($data);
}
@@ -171,6 +226,21 @@ class BudgetController extends Controller
$shared = $shared == 'shared' ? true : false;
$budgets = $repository->getBudgets();
+ // chart properties for cache:
+ $chartProperties = new ChartProperties();
+ $chartProperties->addProperty($start);
+ $chartProperties->addProperty($end);
+ $chartProperties->addProperty('budget');
+ $chartProperties->addProperty('year');
+ $md5 = $chartProperties->md5();
+
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
// add columns:
$chart->addColumn(trans('firefly.month'), 'date');
foreach ($budgets as $budget) {
@@ -196,6 +266,9 @@ class BudgetController extends Controller
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+
+ return Response::json($data);
}
}
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index c6f42cad5b..8c076a1791 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -3,11 +3,14 @@
namespace FireflyIII\Http\Controllers\Chart;
+use Cache;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
+use FireflyIII\Support\ChartProperties;
use Grumpydictator\Gchart\GChart;
+use Log;
use Navigation;
use Preferences;
use Response;
@@ -75,6 +78,22 @@ class CategoryController extends Controller
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
+
+ // chart properties for cache:
+ $chartProperties = new ChartProperties;
+ $chartProperties->addProperty($start);
+ $chartProperties->addProperty($end);
+ $chartProperties->addProperty('category');
+ $chartProperties->addProperty('frontpage');
+ $md5 = $chartProperties->md5();
+
+
+ if (Cache::has($md5)) {
+ Log::debug('Successfully returned cached chart [' . $md5 . '].');
+
+ return Response::json(Cache::get($md5));
+ }
+
$set = $repository->getCategoriesAndExpensesCorrected($start, $end);
// sort by callback:
@@ -99,7 +118,10 @@ class CategoryController extends Controller
$chart->generate();
- return Response::json($chart->getData());
+ $data = $chart->getData();
+ Cache::forever($md5, $data);
+
+ return Response::json($data);
}
diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php
index 6f57851cb9..8f34c5422d 100644
--- a/app/Http/Controllers/CurrencyController.php
+++ b/app/Http/Controllers/CurrencyController.php
@@ -59,6 +59,7 @@ class CurrencyController extends Controller
{
Preferences::set('currencyPreference', $currency->code);
+ Preferences::mark();
Session::flash('success', $currency->name . ' is now the default currency.');
Cache::forget('FFCURRENCYSYMBOL');
@@ -170,6 +171,7 @@ class CurrencyController extends Controller
if (Auth::user()->hasRole('owner')) {
$currency = $repository->store($data);
Session::flash('success', 'Currency "' . $currency->name . '" created');
+
}
if (intval(Input::get('create_another')) === 1) {
@@ -198,6 +200,7 @@ class CurrencyController extends Controller
$currency = $repository->update($currency, $data);
}
Session::flash('success', 'Currency "' . e($currency->name) . '" updated.');
+ Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php
index f7f736065b..7dc2738bcd 100644
--- a/app/Http/Controllers/NewUserController.php
+++ b/app/Http/Controllers/NewUserController.php
@@ -6,6 +6,7 @@ use Config;
use FireflyIII\Http\Requests\NewUserFormRequest;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
+use Preferences;
use Redirect;
use Session;
use View;
@@ -113,6 +114,7 @@ class NewUserController extends Controller
}
Session::flash('success', 'New account(s) created!');
+ Preferences::mark();
return Redirect::route('home');
}
diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php
index 6961b5787b..f9bc5f87c6 100644
--- a/app/Http/Controllers/PiggyBankController.php
+++ b/app/Http/Controllers/PiggyBankController.php
@@ -10,6 +10,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Support\Collection;
use Input;
+use Preferences;
use Redirect;
use Session;
use Steam;
@@ -108,6 +109,7 @@ class PiggyBankController extends Controller
Session::flash('success', 'Piggy bank "' . e($piggyBank->name) . '" deleted.');
+ Preferences::mark();
$repository->destroy($piggyBank);
return Redirect::to(Session::get('piggy-banks.delete.url'));
@@ -208,6 +210,7 @@ class PiggyBankController extends Controller
// set all users piggy banks to zero:
$repository->reset();
+
if (is_array($data)) {
foreach ($data as $order => $id) {
$repository->setOrder(intval($id), (intval($order) + 1));
@@ -240,6 +243,7 @@ class PiggyBankController extends Controller
$repository->createEvent($piggyBank, $amount);
Session::flash('success', 'Added ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".');
+ Preferences::mark();
} else {
Session::flash('error', 'Could not add ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".');
}
@@ -268,6 +272,7 @@ class PiggyBankController extends Controller
$repository->createEvent($piggyBank, $amount * -1);
Session::flash('success', 'Removed ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".');
+ Preferences::mark();
} else {
Session::flash('error', 'Could not remove ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".');
}
@@ -328,6 +333,7 @@ class PiggyBankController extends Controller
$piggyBank = $repository->store($piggyBankData);
Session::flash('success', 'Stored piggy bank "' . e($piggyBank->name) . '".');
+ Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
Session::put('piggy-banks.create.fromStore', true);
@@ -362,6 +368,7 @@ class PiggyBankController extends Controller
$piggyBank = $repository->update($piggyBank, $piggyBankData);
Session::flash('success', 'Updated piggy bank "' . e($piggyBank->name) . '".');
+ Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
Session::put('piggy-banks.edit.fromUpdate', true);
diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php
index 0848155a01..5fd6e4fd24 100644
--- a/app/Http/Controllers/PreferencesController.php
+++ b/app/Http/Controllers/PreferencesController.php
@@ -77,6 +77,7 @@ class PreferencesController extends Controller
Session::flash('success', 'Preferences saved!');
+ Preferences::mark();
return Redirect::route('preferences');
}
diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php
index 8473f1d5e3..ad3423fb1e 100644
--- a/app/Http/Controllers/TagController.php
+++ b/app/Http/Controllers/TagController.php
@@ -106,6 +106,7 @@ class TagController extends Controller
$repository->destroy($tag);
Session::flash('success', 'Tag "' . e($tagName) . '" was deleted.');
+ Preferences::mark();
return Redirect::to(route('tags.index'));
}
@@ -226,6 +227,7 @@ class TagController extends Controller
$repository->store($data);
Session::flash('success', 'The tag has been created!');
+ Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
@@ -271,6 +273,7 @@ class TagController extends Controller
$repository->update($tag, $data);
Session::flash('success', 'Tag "' . e($data['tag']) . '" updated.');
+ Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index 223dab527a..575d35c383 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -11,6 +11,7 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Input;
+use Preferences;
use Redirect;
use Response;
use Session;
@@ -104,6 +105,8 @@ class TransactionController extends Controller
$repository->delete($transactionJournal);
+ Preferences::mark();
+
// redirect to previous URL:
return Redirect::to(Session::get('transactions.delete.url'));
}
@@ -235,6 +238,7 @@ class TransactionController extends Controller
}
}
}
+ Preferences::mark();
return Response::json([true]);
@@ -281,6 +285,7 @@ class TransactionController extends Controller
$repository->deactivateReminder($request->get('reminder_id'));
Session::flash('success', 'New transaction "' . $journal->description . '" stored!');
+ Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
@@ -312,6 +317,7 @@ class TransactionController extends Controller
// update, get events by date and sort DESC
Session::flash('success', 'Transaction "' . e($journalData['description']) . '" updated.');
+ Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
diff --git a/app/Support/ChartProperties.php b/app/Support/ChartProperties.php
index 2b128274fa..e12d864808 100644
--- a/app/Support/ChartProperties.php
+++ b/app/Support/ChartProperties.php
@@ -3,9 +3,11 @@
namespace FireflyIII\Support;
+use Auth;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
+use Preferences;
/**
* Class ChartProperties
@@ -24,6 +26,8 @@ class ChartProperties
public function __construct()
{
$this->properties = new Collection;
+ $this->addProperty(Auth::user()->id);
+ $this->addProperty(Preferences::lastActivity());
}
/**
@@ -41,25 +45,33 @@ class ChartProperties
public function md5()
{
$string = '';
+ //Log::debug('--- building string ---');
foreach ($this->properties as $property) {
if ($property instanceof Collection || $property instanceof EloquentCollection) {
$string .= print_r($property->toArray(), true);
+ // Log::debug('added collection (size=' . $property->count() . ')');
continue;
}
if ($property instanceof Carbon) {
$string .= $property->toRfc3339String();
+ // Log::debug('Added time: ' . $property->toRfc3339String());
continue;
}
if (is_object($property)) {
$string .= $property->__toString();
+ // Log::debug('Added object of class ' . get_class($property));
}
if (is_array($property)) {
$string .= print_r($property, true);
+ // Log::debug('Added array (size=' . count($property) . ')');
}
$string .= (string)$property;
+ // Log::debug('Added cast to string: ' . $property);
}
+ // Log::debug('--- done building string ---');
+
return md5($string);
}
}
\ No newline at end of file
diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php
index 3d53d9c16a..bf781877d7 100644
--- a/app/Support/Preferences.php
+++ b/app/Support/Preferences.php
@@ -4,7 +4,7 @@ namespace FireflyIII\Support;
use Auth;
use FireflyIII\Models\Preference;
-
+use Log;
/**
* Class Preferences
*
@@ -12,6 +12,25 @@ use FireflyIII\Models\Preference;
*/
class Preferences
{
+ /**
+ * @return string
+ */
+ public function lastActivity()
+ {
+ $preference = $this->get('lastActivity', microtime())->data;
+
+ return md5($preference);
+ }
+
+ /**
+ * @return bool
+ */
+ public function mark() {
+ Log::debug('MARK!');
+ $this->set('lastActivity',microtime());
+ return true;
+ }
+
/**
* @param $name
* @param null $default