From 56badea5971212fbeb168111cd4ead2d9a9e69b0 Mon Sep 17 00:00:00 2001 From: Max Lohrmann Date: Wed, 7 Dec 2016 02:58:03 +0100 Subject: Change the behavior of user manager to only update values that actually changed when editing users (part of #2229) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (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) --- Source/SPUserManager.m | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'Source/SPUserManager.m') diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index ede7e7a9..3fe37ae7 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -1156,17 +1156,15 @@ static NSString * const SPTableViewNameColumnID = @"NameColumn"; NSString *dbName = [schemaPriv valueForKey:@"db"]; dbName = [dbName stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"]; - NSString *statement = [NSString stringWithFormat:@"SELECT USER, HOST FROM mysql.db WHERE USER = %@ AND HOST = %@ AND DB = %@", - [[schemaPriv valueForKeyPath:@"user.parent.user"] tickQuotedString], - [[schemaPriv valueForKeyPath:@"user.host"] tickQuotedString], - [dbName tickQuotedString]]; - - NSArray *matchingUsers = [connection getAllRowsFromQuery:statement]; + NSArray *changedKeys = [[schemaPriv changedValues] allKeys]; for (NSString *key in [self privsSupportedByServer]) { if (![key hasSuffix:@"_priv"]) continue; + //ignore anything that we didn't change + if (![changedKeys containsObject:key]) continue; + NSString *privilege = [key stringByReplacingOccurrencesOfString:@"_priv" withString:@""]; NS_DURING @@ -1174,9 +1172,7 @@ static NSString * const SPTableViewNameColumnID = @"NameColumn"; [grantPrivileges addObject:[privilege replaceUnderscoreWithSpace]]; } else { - if ([matchingUsers count] || [grantPrivileges count] > 0) { - [revokePrivileges addObject:[privilege replaceUnderscoreWithSpace]]; - } + [revokePrivileges addObject:[privilege replaceUnderscoreWithSpace]]; } NS_HANDLER NS_ENDHANDLER @@ -1236,10 +1232,15 @@ static NSString * const SPTableViewNameColumnID = @"NameColumn"; NSMutableArray *grantPrivileges = [NSMutableArray array]; NSMutableArray *revokePrivileges = [NSMutableArray array]; + NSArray *changedKeys = [[user changedValues] allKeys]; + for (NSString *key in [self privsSupportedByServer]) { if (![key hasSuffix:@"_priv"]) continue; + //ignore anything that we didn't change + if (![changedKeys containsObject:key]) continue; + NSString *privilege = [key stringByReplacingOccurrencesOfString:@"_priv" withString:@""]; // Check the value of the priv and assign to grant or revoke query as appropriate; do this -- cgit v1.2.3