ViewRevert: avoid needless query

The previous code would call getUserGroups again once creating the log
entry, but this was slightly flawed: we're updating groups on master,
but the read happens on a replica that might be outdated, hence
resulting in broken logging. Instead of reading from master, we can just
keep a list of the groups that were actually added, and use that
afterwards.

Change-Id: I7cc282e15561de3a3d3e183808a65991aa27d2bb
This commit is contained in:
Daimona Eaytoy 2020-10-25 10:28:38 +01:00
parent 8fe9902af3
commit 6c9fc516aa

View file

@ -323,14 +323,16 @@ class AbuseFilterViewRevert extends AbuseFilterView {
$user = User::newFromId( $result['userid'] );
$currentGroups = $userGroupsManager->getUserGroups( $user );
$done = false;
$addedGroups = [];
foreach ( $removedGroups as $group ) {
// TODO An addUserToGroups method with bulk updates would be nice
$done = $userGroupsManager->addUserToGroup( $user, $group ) || $done;
if ( $userGroupsManager->addUserToGroup( $user, $group ) ) {
$addedGroups[] = $group;
}
}
// Don't log if no groups were added.
if ( !$done ) {
if ( !$addedGroups ) {
return false;
}
@ -347,7 +349,7 @@ class AbuseFilterViewRevert extends AbuseFilterView {
);
$logEntry->setParameters( [
'4::oldgroups' => $currentGroups,
'5::newgroups' => $userGroupsManager->getUserGroups( $user )
'5::newgroups' => array_merge( $currentGroups, $addedGroups )
] );
$logEntry->publish( $logEntry->insert() );