Warn about expensive code in test environment.

This commit is contained in:
James Cole
2019-06-22 10:25:57 +02:00
parent 0f70cc5780
commit 2710a30a7c
15 changed files with 328 additions and 127 deletions

View File

@@ -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
*/