Remove references to unused cache thing.

This commit is contained in:
James Cole 2018-01-16 21:09:27 +01:00
parent aa9e8227bb
commit 57855b1930
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
8 changed files with 32 additions and 180 deletions

View File

@ -37,6 +37,7 @@ use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\JoinClause;
@ -243,6 +244,18 @@ class JournalCollector implements JournalCollectorInterface
public function getJournals(): Collection
{
$this->run = true;
// find query set in cache.
$hash = hash('sha256', $this->query->toSql());
$key = 'query-' . substr($hash, -8);
$cache = new CacheProperties;
$cache->addProperty($key);
if ($cache->has()) {
Log::debug(sprintf('Return cache of query with ID "%s".', $key));
return $cache->get(); // @codeCoverageIgnore
}
/** @var Collection $set */
$set = $this->query->get(array_values($this->fields));
@ -263,6 +276,8 @@ class JournalCollector implements JournalCollectorInterface
$transaction->opposing_account_iban = app('steam')->tryDecrypt($transaction->opposing_account_iban);
}
);
Log::debug(sprintf('Cached query with ID "%s".', $key));
$cache->store($set);
return $set;
}
@ -284,6 +299,14 @@ class JournalCollector implements JournalCollectorInterface
return $journals;
}
/**
* @return EloquentBuilder
*/
public function getQuery(): EloquentBuilder
{
return $this->query;
}
/**
* @param string $filter
*

View File

@ -27,6 +27,7 @@ use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
@ -78,6 +79,8 @@ interface JournalCollectorInterface
*/
public function getPaginatedJournals(): LengthAwarePaginator;
public function getQuery(): EloquentBuilder;
/**
* @param string $filter
*

View File

@ -202,8 +202,8 @@ class HomeController extends Controller
'rules.select', 'search.search', 'test-flash', 'transactions.link.delete', 'transactions.link.switch',
'two-factor.lost', 'reports.options', 'debug', 'import.create-job', 'import.download', 'import.start', 'import.status.json',
'preferences.delete-code', 'rules.test-triggers', 'piggy-banks.remove-money', 'piggy-banks.add-money',
'accounts.reconcile.transactions', 'accounts.reconcile.overview','export.download',
'transactions.clone','two-factor.index'
'accounts.reconcile.transactions', 'accounts.reconcile.overview', 'export.download',
'transactions.clone', 'two-factor.index',
];
$return = ' ';
/** @var Route $route */
@ -223,6 +223,7 @@ class HomeController extends Controller
}
}
}
return $return;
}

View File

@ -33,6 +33,7 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Preferences;
/**
* Is capable of storing individual ImportJournal objects.
@ -250,6 +251,7 @@ class ImportStorage
Log::info('Will apply rules to this journal.');
$this->applyRules($journal);
}
Preferences::setForUser($this->job->user, 'lastActivity', microtime());
if (!(true === $this->applyRules)) {
Log::info('Will NOT apply rules to this journal.');
@ -258,7 +260,7 @@ class ImportStorage
// match bills if config calls for it.
if (true === $this->matchBills) {
Log::info('Cannot match bills (yet).');
Log::info('Will match bills.');
$this->matchBills($journal);
}

View File

@ -27,7 +27,6 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\SingleCacheProperties;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\JoinClause;
@ -70,14 +69,6 @@ class JournalTasker implements JournalTaskerInterface
*/
public function getTransactionsOverview(TransactionJournal $journal): array
{
$cache = new SingleCacheProperties;
$cache->addProperty('transaction-overview');
$cache->addProperty($journal->id);
$cache->addProperty($journal->updated_at);
if ($cache->has()) {
return $cache->get();
}
// get all transaction data + the opposite site in one list.
$set = $journal
->transactions()// "source"
->leftJoin(
@ -177,7 +168,6 @@ class JournalTasker implements JournalTaskerInterface
$transactions[] = $transaction;
}
$cache->store($transactions);
return $transactions;
}

View File

@ -1,44 +0,0 @@
<?php
/**
* SingleCacheProperties.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support;
use Illuminate\Support\Collection;
/**
* Class CacheProperties.
*/
class SingleCacheProperties extends CacheProperties
{
/**
*
*/
public function __construct()
{
parent::__construct();
$this->properties = new Collection;
if (auth()->check()) {
$this->addProperty(auth()->user()->id);
$this->addProperty(app('preferences')->lastActivity());
}
}
}

View File

@ -27,7 +27,6 @@ use FireflyIII\Models\Attachment;
use FireflyIII\Models\Transaction as TransactionModel;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\SingleCacheProperties;
use Lang;
use Twig_Extension;
@ -45,14 +44,6 @@ class Transaction extends Twig_Extension
*/
public function amount(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('transaction-amount');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_amount)), '-1');
$format = '%s';
$coloured = true;
@ -97,8 +88,6 @@ class Transaction extends Twig_Extension
$currency->decimal_places = $transaction->foreign_currency_dp;
$str .= ' (' . sprintf($format, app('amount')->formatAnything($currency, $amount, $coloured)) . ')';
}
$cache->store($str);
return $str;
}
@ -109,15 +98,6 @@ class Transaction extends Twig_Extension
*/
public function amountArray(array $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('transaction-array-amount');
$cache->addProperty($transaction['source_id']);
$cache->addProperty($transaction['destination_id']);
$cache->addProperty($transaction['updated_at']);
if ($cache->has()) {
return $cache->get();
}
// first display amount:
$amount = TransactionType::WITHDRAWAL === $transaction['journal_type'] ? $transaction['source_amount']
: $transaction['destination_amount'];
@ -135,8 +115,6 @@ class Transaction extends Twig_Extension
$fakeCurrency->symbol = $transaction['foreign_currency_symbol'];
$string .= ' (' . app('amount')->formatAnything($fakeCurrency, $amount, true) . ')';
}
$cache->store($string);
return $string;
}
@ -147,14 +125,6 @@ class Transaction extends Twig_Extension
*/
public function budgets(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('transaction-budgets');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
// journal has a budget:
if (isset($transaction->transaction_journal_budget_id)) {
$name = app('steam')->tryDecrypt($transaction->transaction_journal_budget_name);
@ -185,12 +155,10 @@ class Transaction extends Twig_Extension
}
$txt = join(', ', $str);
$cache->store($txt);
return $txt;
}
$txt = '';
$cache->store($txt);
return $txt;
}
@ -202,19 +170,10 @@ class Transaction extends Twig_Extension
*/
public function categories(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('transaction-categories');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
// journal has a category:
if (isset($transaction->transaction_journal_category_id)) {
$name = app('steam')->tryDecrypt($transaction->transaction_journal_category_name);
$txt = sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_journal_category_id]), $name, $name);
$cache->store($txt);
return $txt;
}
@ -223,7 +182,6 @@ class Transaction extends Twig_Extension
if (isset($transaction->transaction_category_id)) {
$name = app('steam')->tryDecrypt($transaction->transaction_category_name);
$txt = sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_category_id]), $name, $name);
$cache->store($txt);
return $txt;
}
@ -240,14 +198,11 @@ class Transaction extends Twig_Extension
}
$txt = join(', ', $str);
$cache->store($txt);
return $txt;
}
$txt = '';
$cache->store($txt);
return $txt;
}
@ -258,20 +213,11 @@ class Transaction extends Twig_Extension
*/
public function description(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('description');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
$description = $transaction->description;
if (strlen(strval($transaction->transaction_description)) > 0) {
$description = $transaction->transaction_description . '(' . $transaction->description . ')';
}
$cache->store($description);
return $description;
}
@ -282,14 +228,6 @@ class Transaction extends Twig_Extension
*/
public function destinationAccount(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('transaction-destination');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
if (TransactionType::RECONCILIATION === $transaction->transaction_type_type) {
return '&mdash;';
}
@ -325,13 +263,11 @@ class Transaction extends Twig_Extension
if (AccountType::CASH === $type) {
$txt = '<span class="text-success">(' . trans('firefly.cash') . ')</span>';
$cache->store($txt);
return $txt;
}
$txt = sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$transactionId]));
$cache->store($txt);
return $txt;
}
@ -343,13 +279,6 @@ class Transaction extends Twig_Extension
*/
public function hasAttachments(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('attachments');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
$journalId = intval($transaction->journal_id);
$count = Attachment::whereNull('deleted_at')
->where('attachable_type', 'FireflyIII\Models\TransactionJournal')
@ -357,13 +286,11 @@ class Transaction extends Twig_Extension
->count();
if ($count > 0) {
$res = sprintf('<i class="fa fa-paperclip" title="%s"></i>', Lang::choice('firefly.nr_of_attachments', $count, ['count' => $count]));
$cache->store($res);
return $res;
}
$res = '';
$cache->store($res);
return $res;
}
@ -375,14 +302,6 @@ class Transaction extends Twig_Extension
*/
public function icon(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('icon');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
switch ($transaction->transaction_type_type) {
case TransactionType::WITHDRAWAL:
$txt = sprintf('<i class="fa fa-long-arrow-left fa-fw" title="%s"></i>', trans('firefly.withdrawal'));
@ -403,7 +322,6 @@ class Transaction extends Twig_Extension
$txt = '';
break;
}
$cache->store($txt);
return $txt;
}
@ -415,21 +333,11 @@ class Transaction extends Twig_Extension
*/
public function isReconciled(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('transaction-reconciled');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
$cache->addProperty($transaction->reconciled);
if ($cache->has()) {
return $cache->get();
}
$icon = '';
if (1 === intval($transaction->reconciled)) {
$icon = '<i class="fa fa-check"></i>';
}
$cache->store($icon);
return $icon;
}
@ -440,25 +348,14 @@ class Transaction extends Twig_Extension
*/
public function isSplit(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('split');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
$journalId = intval($transaction->journal_id);
$count = TransactionModel::where('transaction_journal_id', $journalId)->whereNull('deleted_at')->count();
if ($count > 2) {
$res = '<i class="fa fa-fw fa-share-alt" aria-hidden="true"></i>';
$cache->store($res);
return $res;
}
$res = '';
$cache->store($res);
return $res;
}
@ -469,13 +366,6 @@ class Transaction extends Twig_Extension
*/
public function sourceAccount(TransactionModel $transaction): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('transaction-source');
$cache->addProperty($transaction->id);
$cache->addProperty($transaction->updated_at);
if ($cache->has()) {
return $cache->get();
}
if (TransactionType::RECONCILIATION === $transaction->transaction_type_type) {
return '&mdash;';
}
@ -510,14 +400,11 @@ class Transaction extends Twig_Extension
if (AccountType::CASH === $type) {
$txt = '<span class="text-success">(' . trans('firefly.cash') . ')</span>';
$cache->store($txt);
return $txt;
}
$txt = sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$transactionId]));
$cache->store($txt);
return $txt;
}
}

View File

@ -25,7 +25,6 @@ namespace FireflyIII\Support\Twig\Extension;
use FireflyIII\Models\Transaction as TransactionModel;
use FireflyIII\Models\TransactionJournal as JournalModel;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\SingleCacheProperties;
use Twig_Extension;
/**
@ -40,14 +39,6 @@ class TransactionJournal extends Twig_Extension
*/
public function totalAmount(JournalModel $journal): string
{
$cache = new SingleCacheProperties;
$cache->addProperty('total-amount');
$cache->addProperty($journal->id);
$cache->addProperty($journal->updated_at);
if ($cache->has()) {
return $cache->get();
}
$transactions = $journal->transactions()->where('amount', '>', 0)->get();
$totals = [];
$type = $journal->transactionType->type;
@ -84,7 +75,6 @@ class TransactionJournal extends Twig_Extension
$array[] = app('amount')->formatAnything($total['currency'], $total['amount']);
}
$txt = join(' / ', $array);
$cache->store($txt);
return $txt;
}