mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Warn about expensive code in test environment.
This commit is contained in:
@@ -36,13 +36,16 @@ use Session;
|
||||
class Preferences
|
||||
{
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @param string $search
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function beginsWith(User $user, string $search): Collection
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$set = Preference::where('user_id', $user->id)->where('name', 'LIKE', $search . '%')->get();
|
||||
|
||||
return $set;
|
||||
@@ -55,6 +58,9 @@ class Preferences
|
||||
*/
|
||||
public function delete(string $name): bool
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$fullName = sprintf('preference%s%s', auth()->user()->id, $name);
|
||||
if (Cache::has($fullName)) {
|
||||
Cache::forget($fullName);
|
||||
@@ -76,17 +82,24 @@ class Preferences
|
||||
*/
|
||||
public function findByName(string $name): Collection
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
|
||||
return Preference::where('name', $name)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return \FireflyIII\Models\Preference|null
|
||||
*/
|
||||
public function get(string $name, $default = null): ?Preference
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
if (null === $user) {
|
||||
@@ -98,12 +111,15 @@ class Preferences
|
||||
|
||||
/**
|
||||
* @param \FireflyIII\User $user
|
||||
* @param array $list
|
||||
* @param array $list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArrayForUser(User $user, array $list): array
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$result = [];
|
||||
$preferences = Preference::where('user_id', $user->id)->whereIn('name', $list)->get(['id', 'name', 'data']);
|
||||
/** @var Preference $preference */
|
||||
@@ -121,13 +137,16 @@ class Preferences
|
||||
|
||||
/**
|
||||
* @param \FireflyIII\User $user
|
||||
* @param string $name
|
||||
* @param null|string $default
|
||||
* @param string $name
|
||||
* @param null|string $default
|
||||
*
|
||||
* @return \FireflyIII\Models\Preference|null
|
||||
*/
|
||||
public function getForUser(User $user, string $name, $default = null): ?Preference
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$fullName = sprintf('preference%s%s', $user->id, $name);
|
||||
if (Cache::has($fullName)) {
|
||||
return Cache::get($fullName);
|
||||
@@ -162,6 +181,9 @@ class Preferences
|
||||
*/
|
||||
public function lastActivity(): string
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$lastActivity = microtime();
|
||||
$preference = $this->get('lastActivity', microtime());
|
||||
|
||||
@@ -186,7 +208,7 @@ class Preferences
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return \FireflyIII\Models\Preference
|
||||
*/
|
||||
@@ -207,8 +229,8 @@ class Preferences
|
||||
|
||||
/**
|
||||
* @param \FireflyIII\User $user
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Preference
|
||||
*/
|
||||
|
Reference in New Issue
Block a user