-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IUserPreferences #47658
base: master
Are you sure you want to change the base?
IUserPreferences #47658
Conversation
6d81b97
to
a9e2a38
Compare
e9ec009
to
cda7029
Compare
1fbb6a9
to
317202a
Compare
c78f304
to
979ecee
Compare
979ecee
to
41ba78f
Compare
8edb1c1
to
e510535
Compare
f71bb7d
to
e24d29a
Compare
32c209d
to
b80315b
Compare
b80315b
to
0c489af
Compare
0c489af
to
6ae7f9f
Compare
ceb814d
to
a219133
Compare
lib/private/UserPreferences.php
Outdated
$value = $cache[$app][$key]; | ||
try { | ||
$this->decryptSensitiveValue($userId, $app, $key, $value); | ||
$value = $this->convertTypedValue($value, $typedAs ?? $this->getValueType($userId, (string)$app, $key, $lazy)); |
Check failure
Code scanning / Psalm
RedundantCast
* @param string $value preference value | ||
* @param bool $caseInsensitive non-case-sensitive search, only works if $value is a string | ||
* | ||
* @return list<string> |
Check failure
Code scanning / Psalm
MoreSpecificReturnType
* @since 31.0.0 | ||
*/ | ||
public function searchUsersByValueString(string $app, string $key, string $value, bool $caseInsensitive = false): array { | ||
return $this->searchUsersByTypedValue($app, $key, $value, $caseInsensitive); |
Check failure
Code scanning / Psalm
LessSpecificReturnStatement
* @param string $key preference key | ||
* @param array $values list of preference values | ||
* | ||
* @return list<string> |
Check failure
Code scanning / Psalm
MoreSpecificReturnType
* @since 31.0.0 | ||
*/ | ||
public function searchUsersByValues(string $app, string $key, array $values): array { | ||
return $this->searchUsersByTypedValue($app, $key, $values); |
Check failure
Code scanning / Psalm
LessSpecificReturnStatement
9010cc6
to
cc4a1ff
Compare
Signed-off-by: Maxence Lange <[email protected]>
cc4a1ff
to
da769f0
Compare
@@ -463,31 +365,10 @@ public function getUserValueForUsers($appName, $key, $userIds) { | |||
* @param string $key the key to get the user for | |||
* @param string $value the value to get the user for | |||
* @return list<string> of user IDs | |||
* @deprecated 31.0.0 - use {@see IUserPreferences} directly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you specify the replacement method for the deprecated ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, please split that file before it gets out of hand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, split the type and the flags to two distinct columns.
type
with values 1, 2, 3, 4, ...
. That could also be some flag values, but then drop the MIXED
type value
flags
with value 1, 2, 4, 8, ...
or any combination of them.
|
||
$qb = $this->connection->getQueryBuilder(); | ||
$qb->from('preferences'); | ||
$qb->select('userid', 'appid', 'configkey', 'configvalue', 'type'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For "extra" perf, don't select the userid
column and use the $userId
var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stopped at line 1050 of UserPreferences, to be continued…
I dislike the sensitive flag thing, it should be a bool just like lazy so that all types var can be typed to the enum.
$this->userCache[$userId][$appName][$key] = (string)$value; | ||
return; | ||
/** @var UserPreferences $userPreferences */ | ||
$userPreferences = \OC::$server->get(IUserPreferences::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$userPreferences = \OC::$server->get(IUserPreferences::class); | |
$userPreferences = \OCP\Server::get(IUserPreferences::class); |
return $default; | ||
} | ||
/** @var UserPreferences $userPreferences */ | ||
$userPreferences = \OC::$server->get(IUserPreferences::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
} else { | ||
return []; | ||
} | ||
return \OC::$server->get(IUserPreferences::class)->getKeys($userId, $appName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inject it if you use it more than twice :-P
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid cluttering OC namespace please
if ($valueType !== null) { | ||
$valueFlag = $valueType->value; | ||
$valueFlag &= ~ValueType::SENSITIVE->value; | ||
if (ValueType::tryFrom($valueFlag) === null) { | ||
throw new InvalidArgumentException('Unknown value type'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not make sense with an enum
$rows = $result->fetchAll(); | ||
foreach ($rows as $row) { | ||
$userIds[] = $row['userid']; | ||
} | ||
|
||
return $userIds; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$rows = $result->fetchAll(); | |
foreach ($rows as $row) { | |
$userIds[] = $row['userid']; | |
} | |
return $userIds; | |
while ($row = $result->fetch()) { | |
yield $row['userid']; | |
} |
?bool $lazy = false, | ||
): string { | ||
try { | ||
$lazy = ($lazy === null) ? $this->isLazy($userId, $app, $key) : $lazy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$lazy = ($lazy === null) ? $this->isLazy($userId, $app, $key) : $lazy; | |
$lazy ??= $this->isLazy($userId, $app, $key); |
/** | ||
* convert bitflag from value type to ValueType | ||
* | ||
* @param int $type | ||
* | ||
* @return ValueType | ||
* @throws IncorrectTypeException | ||
*/ | ||
private function extractValueType(int $type): ValueType { | ||
$type &= ~ValueType::SENSITIVE->value; | ||
|
||
try { | ||
return ValueType::from($type); | ||
} catch (ValueError) { | ||
throw new IncorrectTypeException('invalid value type'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugly
} | ||
|
||
/** | ||
* This should only happen during the upgrade process from 28 to 29. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit late for that.
* We only log a warning and set it to VALUE_MIXED. | ||
*/ | ||
if ($currType === 0) { | ||
$this->logger->warning('Value type is set to zero (0) in database. This is fine only during the upgrade process from 28 to 29.', ['app' => $app, 'key' => $key]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->logger->warning('Value type is set to zero (0) in database. This is fine only during the upgrade process from 28 to 29.', ['app' => $app, 'key' => $key]); | |
$this->logger->warning('Value type is set to zero (0) in database. This is fine only during the upgrade process from 30 to 31.', ['app' => $app, 'key' => $key]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe let's keep it private for one major version to have the flexibility to change the API down the road?
IConfig
's preferences-related method