aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Lohrmann <dmoagx@users.noreply.github.com>2016-12-07 02:58:03 +0100
committerMax Lohrmann <dmoagx@users.noreply.github.com>2016-12-07 02:58:03 +0100
commit56badea5971212fbeb168111cd4ead2d9a9e69b0 (patch)
tree7d2e2c6c9e07404e171e038c9d07dd7faca32889
parent9eab47a175ae046da37d3dd6dedc8d8ba40e3b21 (diff)
downloadsequelpro-56badea5971212fbeb168111cd4ead2d9a9e69b0.tar.gz
sequelpro-56badea5971212fbeb168111cd4ead2d9a9e69b0.tar.bz2
sequelpro-56badea5971212fbeb168111cd4ead2d9a9e69b0.zip
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)
-rw-r--r--Source/SPUserManager.m19
1 files changed, 10 insertions, 9 deletions
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