Skip to content

Commit 56badea

Browse files
committed
Change the behavior of user manager to only update values that actually changed when editing users (part of #2229)
(This also removes an additional db roundtrip when updating per-db user privileges that previously was needed to differentiate between user actions „Only removing privileges from user“ and „Backtracking on adding privileges to user“. Since we now only update changed values and the latter one would be an empty changeset this is no longer needed)
1 parent 9eab47a commit 56badea

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Source/SPUserManager.m

+10-9
Original file line numberDiff line numberDiff line change
@@ -1156,27 +1156,23 @@ - (BOOL)grantDbPrivilegesWithPrivilege:(SPPrivilegesMO *)schemaPriv skippingRevo
11561156
NSString *dbName = [schemaPriv valueForKey:@"db"];
11571157
dbName = [dbName stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"];
11581158

1159-
NSString *statement = [NSString stringWithFormat:@"SELECT USER, HOST FROM mysql.db WHERE USER = %@ AND HOST = %@ AND DB = %@",
1160-
[[schemaPriv valueForKeyPath:@"user.parent.user"] tickQuotedString],
1161-
[[schemaPriv valueForKeyPath:@"user.host"] tickQuotedString],
1162-
[dbName tickQuotedString]];
1163-
1164-
NSArray *matchingUsers = [connection getAllRowsFromQuery:statement];
1159+
NSArray *changedKeys = [[schemaPriv changedValues] allKeys];
11651160

11661161
for (NSString *key in [self privsSupportedByServer])
11671162
{
11681163
if (![key hasSuffix:@"_priv"]) continue;
11691164

1165+
//ignore anything that we didn't change
1166+
if (![changedKeys containsObject:key]) continue;
1167+
11701168
NSString *privilege = [key stringByReplacingOccurrencesOfString:@"_priv" withString:@""];
11711169

11721170
NS_DURING
11731171
if ([[schemaPriv valueForKey:key] boolValue] == YES) {
11741172
[grantPrivileges addObject:[privilege replaceUnderscoreWithSpace]];
11751173
}
11761174
else {
1177-
if ([matchingUsers count] || [grantPrivileges count] > 0) {
1178-
[revokePrivileges addObject:[privilege replaceUnderscoreWithSpace]];
1179-
}
1175+
[revokePrivileges addObject:[privilege replaceUnderscoreWithSpace]];
11801176
}
11811177
NS_HANDLER
11821178
NS_ENDHANDLER
@@ -1236,10 +1232,15 @@ - (BOOL)grantPrivilegesToUser:(SPUserMO *)user skippingRevoke:(BOOL)skipRevoke
12361232
NSMutableArray *grantPrivileges = [NSMutableArray array];
12371233
NSMutableArray *revokePrivileges = [NSMutableArray array];
12381234

1235+
NSArray *changedKeys = [[user changedValues] allKeys];
1236+
12391237
for (NSString *key in [self privsSupportedByServer])
12401238
{
12411239
if (![key hasSuffix:@"_priv"]) continue;
12421240

1241+
//ignore anything that we didn't change
1242+
if (![changedKeys containsObject:key]) continue;
1243+
12431244
NSString *privilege = [key stringByReplacingOccurrencesOfString:@"_priv" withString:@""];
12441245

12451246
// Check the value of the priv and assign to grant or revoke query as appropriate; do this

0 commit comments

Comments
 (0)