Permalink
Browse files

Remove a superfluous ivar and the unholy intermingling of UI and data…

… code it has caused (part of #2770)
  • Loading branch information...
dmoagx committed Apr 17, 2017
1 parent e1b881b commit dfab0cd76c54ba3f78284a57c89a7585a6042a38
Showing with 18 additions and 24 deletions.
  1. +0 −1 Source/SPCustomQuery.h
  2. +18 −23 Source/SPCustomQuery.m
View
@@ -160,7 +160,6 @@
SPDataStorage *resultData;
pthread_mutex_t resultDataLock;
NSInteger resultDataCount;
NSArray *cqColumnDefinition;
NSString *lastExecutedQuery;
NSInteger editedRow;
View
@@ -61,6 +61,7 @@
#import "SPAppController.h"
#import "SPBundleHTMLOutputController.h"
#endif
#import "SPFunctions.h"
#import <pthread.h>
#import <SPMySQL/SPMySQL.h>
@@ -884,7 +885,7 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
(long)totalAffectedRows
];
}
if(resultDataCount) {
if([resultData count]) {
// we were running a query that returns a result set (ie. SELECT).
// TODO: mysql_query() returns as soon as the first result row is found (which might be pretty soon when using indexes / not doing aggregations)
// and that makes our query time measurement pretty useless (see #264)
@@ -905,7 +906,7 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
#endif
// If no results were returned, redraw the empty table and post notifications before returning.
if ( !resultDataCount ) {
if ( ![resultData count] ) {
[customQueryView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
// Notify any listeners that the query has completed
@@ -931,8 +932,6 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
return;
}
[[customQueryView onMainThread] reloadData];
// Restore the result view origin if appropriate
if (!NSEqualRects(selectionViewportToRestore, NSZeroRect)) {
@@ -976,12 +975,12 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
*/
- (void)updateResultStore:(SPMySQLStreamingResultStore *)theResultStore
{
// Remove all items from the table
resultDataCount = 0;
[customQueryView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES];
pthread_mutex_lock(&resultDataLock);
[resultData removeAllRows];
// Remove all items from the table
SPMainQSync(^{
[resultData removeAllRows];
[customQueryView noteNumberOfRowsChanged];
});
// Add the new store
[resultData setDataStorage:theResultStore updatingExisting:NO];
@@ -994,11 +993,8 @@ - (void)updateResultStore:(SPMySQLStreamingResultStore *)theResultStore
[[self onMainThread] initQueryLoadTimer];
[resultData awaitDataDownloaded];
// If the final column autoresize wasn't performed, perform it
if (queryLoadLastRowCount < 200) [[self onMainThread] autosizeColumns];
[customQueryView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:NO];
// Any further UI updates are the responsibility of the timer callback
}
/**
@@ -1488,8 +1484,8 @@ - (void) clearQueryLoadTimer
*/
- (void) queryLoadUpdate:(NSTimer *)theTimer
{
resultDataCount = [resultData count];
NSUInteger resultDataCount = [resultData count];
if (queryLoadTimerTicksSinceLastUpdate < queryLoadInterfaceUpdateInterval) {
queryLoadTimerTicksSinceLastUpdate++;
return;
@@ -1501,7 +1497,7 @@ - (void) queryLoadUpdate:(NSTimer *)theTimer
// Check whether a table update is required, based on whether new rows are
// available to display.
if (resultDataCount == (NSInteger)queryLoadLastRowCount) {
if (resultDataCount == queryLoadLastRowCount) {
return;
}
@@ -1548,7 +1544,7 @@ - (NSArray *)currentResult
*/
- (NSUInteger)currentResultRowCount
{
return resultDataCount;
return [resultData count];
}
/**
@@ -2077,7 +2073,7 @@ - (void)saveCellValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn
*/
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return (aTableView == customQueryView) ? (resultData == nil) ? 0 : resultDataCount : 0;
return (aTableView == customQueryView) ? (resultData == nil) ? 0 : [resultData count] : 0;
}
/**
@@ -2102,7 +2098,7 @@ - (void)tableView:(SPCopyTable *)aTableView willDisplayCell:(id)cell forTableCol
if (isWorking) {
pthread_mutex_lock(&resultDataLock);
if (rowIndex < resultDataCount && columnIndex < [resultData columnCount]) {
if (SPIntS2U(rowIndex) < [resultData count] && columnIndex < [resultData columnCount]) {
showCellAsGray = [resultData cellIsNullOrUnloadedAtRow:rowIndex column:columnIndex];
} else {
showCellAsGray = YES;
@@ -2403,7 +2399,7 @@ - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(SPTextAndLinkC
// cases.
if (isWorking) {
pthread_mutex_lock(&resultDataLock);
if (row < resultDataCount && (NSUInteger)[[aTableColumn identifier] integerValue] < [resultData columnCount]) {
if (SPIntS2U(row) < [resultData count] && (NSUInteger)[[aTableColumn identifier] integerValue] < [resultData columnCount]) {
theValue = [[SPDataStorageObjectAtRowAndColumn(resultData, row, [[aTableColumn identifier] integerValue]) copy] autorelease];
}
pthread_mutex_unlock(&resultDataLock);
@@ -3769,7 +3765,6 @@ - (id)init
#endif
// init tableView's data source
resultDataCount = 0;
resultData = [[SPDataStorage alloc] init];
editedRow = -1;
@@ -4022,7 +4017,7 @@ - (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column preserv
if (isWorking) {
pthread_mutex_lock(&resultDataLock);
if (row < resultDataCount && column < [resultData columnCount]) {
if (SPIntS2U(row) < [resultData count] && column < [resultData columnCount]) {
value = SPDataStoragePreviewAtRowAndColumn(resultData, row, column, 150);
}

0 comments on commit dfab0cd

Please sign in to comment.