25 if ( !$user->getId() ) {
29 $dbr = DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $recency );
30 $res = $dbr->newSelectQueryBuilder()
31 ->select( [
'up_property',
'up_value' ] )
32 ->from(
'user_properties' )
33 ->where( [
'up_user' => $user->getId() ] )
35 ->caller( __METHOD__ )->fetchResultSet();
38 foreach ( $res as $row ) {
39 $options[$row->up_property] = (string)$row->up_value;
42 $this->optionsFromDb[$user->getId()] = $options;
48 if ( !$user->
getId() ) {
52 $oldOptions = $this->optionsFromDb[ $user->
getId() ]
53 ?? $this->fetch( $user, IDBAccessObject::READ_LATEST );
54 $newOptions = $oldOptions;
57 foreach ( $updates as $key => $value ) {
59 $value, $oldOptions[$key] ??
null )
62 if ( array_key_exists( $key, $oldOptions ) ) {
63 $keysToDelete[] = $key;
64 unset( $newOptions[$key] );
66 if ( $value !==
null ) {
67 $truncValue = mb_strcut( $value, 0,
70 'up_user' => $user->
getId(),
71 'up_property' => $key,
72 'up_value' => $truncValue,
74 $newOptions[$key] = $truncValue;
78 if ( !count( $keysToDelete ) && !count( $rowsToInsert ) ) {
84 $dbw = $this->dbProvider->getPrimaryDatabase();
85 if ( $keysToDelete ) {
86 $dbw->newDeleteQueryBuilder()
87 ->deleteFrom(
'user_properties' )
88 ->where( [
'up_user' => $user->
getId() ] )
89 ->andWhere( [
'up_property' => $keysToDelete ] )
90 ->caller( __METHOD__ )->execute();
92 if ( $rowsToInsert ) {
94 $dbw->newInsertQueryBuilder()
95 ->insertInto(
'user_properties' )
97 ->rows( $rowsToInsert )
98 ->caller( __METHOD__ )->execute();
102 $this->optionsFromDb[$user->
getId()] = $newOptions;