From fbc82502be6a75f0934a2dfe925c94ff0d30d8d2 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 23 Jun 2009 23:28:12 +0000 Subject: - Tweak to table relations to allow data refreshing to optionally clear the master data cache; removes the duplicate CREATE TABLE command on table load, reducing overall queries and so improving speed further --- Source/SPTableRelations.m | 65 +++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'Source/SPTableRelations.m') diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m index a08639f9..757dc991 100644 --- a/Source/SPTableRelations.m +++ b/Source/SPTableRelations.m @@ -33,6 +33,7 @@ @interface SPTableRelations (PrivateAPI) +- (void)_refreshRelationDataForcingCacheRefresh:(BOOL)clearAllCaches; - (void)_updateAvailableTableColumns; @end @@ -170,7 +171,7 @@ [NSString stringWithFormat:NSLocalizedString(@"The specified relation was unable to be created.\n\nMySQL said: %@", @"error creating relation informative message"), [connection getLastErrorMessage]]); } else { - [self refreshRelations:nil]; + [self _refreshRelationDataForcingCacheRefresh:YES]; } } @@ -214,40 +215,17 @@ row = [selectedSet indexLessThanIndex:row]; } - [self refreshRelations:nil]; + [self _refreshRelationDataForcingCacheRefresh:YES]; } } } /** - * Refreshes the displayed relations. + * Trigger a refresh of the displayed relations via the interface. */ - (IBAction)refreshRelations:(id)sender { - [relationData removeAllObjects]; - - if ([tablesListInstance tableType] == SP_TABLETYPE_TABLE) { - - [tableDataInstance updateInformationForCurrentTable]; - - NSArray *constraints = [tableDataInstance getConstraints]; - - for (NSDictionary *constraint in constraints) - { - [relationData addObject:[NSDictionary dictionaryWithObjectsAndKeys: - [tablesListInstance tableName], @"table", - [constraint objectForKey:@"name"], @"name", - [constraint objectForKey:@"columns"], @"columns", - [constraint objectForKey:@"ref_table"], @"fk_table", - [constraint objectForKey:@"ref_columns"], @"fk_columns", - [constraint objectForKey:@"update"], @"on_update", - [constraint objectForKey:@"delete"], @"on_delete", - nil]]; - - } - } - - [relationsTableView reloadData]; + [self _refreshRelationDataForcingCacheRefresh:YES]; } /** @@ -280,7 +258,7 @@ [labelTextField setStringValue:([tablesListInstance tableType] == SP_TABLETYPE_TABLE) ? @"This table does not support relations" : @""]; } - [self refreshRelations:self]; + [self _refreshRelationDataForcingCacheRefresh:NO]; } #pragma mark - @@ -324,6 +302,37 @@ @implementation SPTableRelations (PrivateAPI) +/** + * Refresh the displayed relations, optionally forcing a refresh of the underlying cache. + */ +- (void)_refreshRelationDataForcingCacheRefresh:(BOOL)clearAllCaches +{ + [relationData removeAllObjects]; + + if ([tablesListInstance tableType] == SP_TABLETYPE_TABLE) { + + if (clearAllCaches) [tableDataInstance updateInformationForCurrentTable]; + + NSArray *constraints = [tableDataInstance getConstraints]; + + for (NSDictionary *constraint in constraints) + { + [relationData addObject:[NSDictionary dictionaryWithObjectsAndKeys: + [tablesListInstance tableName], @"table", + [constraint objectForKey:@"name"], @"name", + [constraint objectForKey:@"columns"], @"columns", + [constraint objectForKey:@"ref_table"], @"fk_table", + [constraint objectForKey:@"ref_columns"], @"fk_columns", + [constraint objectForKey:@"update"], @"on_update", + [constraint objectForKey:@"delete"], @"on_delete", + nil]]; + + } + } + + [relationsTableView reloadData]; +} + /** * Updates the available table columns that the reference is pointing to. Available columns are those that are * within the selected table and are of the same data type as the column the reference is from. -- cgit v1.2.3