Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

IUserPreferences #47658

wants to merge 1 commit into from

Conversation

ArtificialOwl
Copy link
Member

@ArtificialOwl ArtificialOwl commented Aug 31, 2024

  • replace IConfig's preferences-related method
  • tests

@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 2 times, most recently from 6d81b97 to a9e2a38 Compare August 31, 2024 22:30
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 2 times, most recently from 8edb1c1 to e510535 Compare September 2, 2024 02:31
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 2 times, most recently from 32c209d to b80315b Compare September 2, 2024 14:57
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl marked this pull request as ready for review September 30, 2024 16:26
@ArtificialOwl ArtificialOwl added the 3. to review Waiting for reviews label Sep 30, 2024
@ArtificialOwl ArtificialOwl added this to the Nextcloud 31 milestone Sep 30, 2024
$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

Redundant cast to string
* @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

The declared return type 'list<string>' for OC\UserPreferences::searchUsersByValueString is more specific than the inferred return type 'array<array-key, mixed>'
* @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

The type 'array<array-key, mixed>' is more general than the declared return type 'list<string>' for OC\UserPreferences::searchUsersByValueString
* @param string $key preference key
* @param array $values list of preference values
*
* @return list<string>

Check failure

Code scanning / Psalm

MoreSpecificReturnType

The declared return type 'list<string>' for OC\UserPreferences::searchUsersByValues is more specific than the inferred return type 'array<array-key, mixed>'
* @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

The type 'array<array-key, mixed>' is more general than the declared return type 'list<string>' for OC\UserPreferences::searchUsersByValues
@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 2 times, most recently from 9010cc6 to cc4a1ff Compare October 3, 2024 13:32
@@ -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
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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');
Copy link
Contributor

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.

Copy link
Contributor

@come-nc come-nc left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$userPreferences = \OC::$server->get(IUserPreferences::class);
$userPreferences = \OCP\Server::get(IUserPreferences::class);

return $default;
}
/** @var UserPreferences $userPreferences */
$userPreferences = \OC::$server->get(IUserPreferences::class);
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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

Comment on lines +1494 to +1500
if ($valueType !== null) {
$valueFlag = $valueType->value;
$valueFlag &= ~ValueType::SENSITIVE->value;
if (ValueType::tryFrom($valueFlag) === null) {
throw new InvalidArgumentException('Unknown value type');
}
}
Copy link
Contributor

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

Comment on lines +455 to +460
$rows = $result->fetchAll();
foreach ($rows as $row) {
$userIds[] = $row['userid'];
}

return $userIds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$lazy = ($lazy === null) ? $this->isLazy($userId, $app, $key) : $lazy;
$lazy ??= $this->isLazy($userId, $app, $key);

Comment on lines +722 to +738
/**
* 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');
}
}
Copy link
Contributor

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.
Copy link
Contributor

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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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]);

Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants