Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #118 from barijaona/database-mainstream

Database on main stream only
  • Loading branch information...
commit 9d5567a514cd73d92c6990de42a9f6b2b6f7f660 2 parents c1a941e + 37f6965
@mstroeck mstroeck authored
View
8 src/AppController.m
@@ -604,9 +604,7 @@ -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
case MA_EmptyTrash_WithoutWarning:
if (![db isTrashEmpty])
{
- [[RefreshManager articlesUpdateSemaphore] lock];
[db purgeDeletedArticles];
- [[RefreshManager articlesUpdateSemaphore] unlock];
}
break;
@@ -617,9 +615,7 @@ -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
emptyTrashWarning = [[EmptyTrashWarning alloc] init];
if ([emptyTrashWarning shouldEmptyTrash])
{
- [[RefreshManager articlesUpdateSemaphore] lock];
[db purgeDeletedArticles];
- [[RefreshManager articlesUpdateSemaphore] unlock];
}
[emptyTrashWarning release];
emptyTrashWarning = nil;
@@ -2028,9 +2024,7 @@ -(void)doConfirmedEmptyTrash:(NSWindow *)sheet returnCode:(int)returnCode contex
if (returnCode == NSAlertDefaultReturn)
{
[self clearUndoStack];
- [[RefreshManager articlesUpdateSemaphore] lock];
[db purgeDeletedArticles];
- [[RefreshManager articlesUpdateSemaphore] unlock];
}
}
@@ -2432,9 +2426,7 @@ -(void)handleRefreshStatusChange:(NSNotification *)nc
{
// Run the auto-expire now
Preferences * prefs = [Preferences standardPreferences];
- [[RefreshManager articlesUpdateSemaphore] lock];
[db purgeArticlesOlderThanDays:[prefs autoExpireDuration]];
- [[RefreshManager articlesUpdateSemaphore] unlock];
[self setStatusMessage:NSLocalizedString(@"Refresh completed", nil) persist:YES];
[self stopProgressIndicator];
View
2  src/ArticleController.m
@@ -312,10 +312,8 @@ -(void)displayFolder:(int)newFolderId
-(void)reloadArrayOfArticles
{
- [[RefreshManager articlesUpdateSemaphore] lock];
Folder * folder = [[Database sharedDatabase] folderFromID:currentFolderId];
[self setFolderArrayOfArticles:[folder articlesWithFilter:[[NSApp delegate] filterString]]];
- [[RefreshManager articlesUpdateSemaphore] unlock];
[self refilterArrayOfArticles];
}
View
86 src/Database.m
@@ -531,12 +531,12 @@ -(NSInteger)executeSQLWithFormat:(NSString *)sqlStatement, ...
}
/* verifyThreadSafety
- * Formerly, in debug mode we asserted if the caller thread wasn't the thread
- * on which the database was created. Now, we just do nothing.
+ * In debug mode we assert if the caller thread isn't the thread on which the database
+ * was created. In release mode, we do nothing.
*/
-(void)verifyThreadSafety
{
- //NSAssert([NSThread currentThread] == mainThread, @"Calling database on wrong thread!");
+ NSAssert([NSThread currentThread] == mainThread, @"Calling database on wrong thread!");
}
/* syncLastUpdate
@@ -1683,13 +1683,13 @@ -(void)initSmartfoldersDict
// Verify we're on the right thread
[self verifyThreadSafety];
- results = [sqlDatabase performQuery:@"select * from smart_folders"];
+ results = [sqlDatabase performQuery:@"select folder_id, search_string from smart_folders"];
if (results && [results rowCount])
{
for (SQLRow * row in [results rowEnumerator])
{
- NSString * search_string = [row stringForColumn:@"search_string"];
- NSInteger folderId = [[row stringForColumn:@"folder_id"] intValue];
+ NSInteger folderId = [[row stringForColumnAtIndex:0] intValue];
+ NSString * search_string = [row stringForColumnAtIndex:1];
CriteriaTree * criteriaTree = [[CriteriaTree alloc] initWithString:search_string];
[smartfoldersDict setObject:criteriaTree forKey:[NSNumber numberWithInt:folderId]];
@@ -1772,20 +1772,21 @@ -(void)initFolderArray
// Verify we're on the right thread
[self verifyThreadSafety];
- results = [sqlDatabase performQuery:@"select * from folders order by folder_id"];
+ results = [sqlDatabase performQuery:@"select folder_id, parent_id, foldername, unread_count, last_update,"
+ @" type, flags, next_sibling, first_child from folders order by folder_id"];
if (results && [results rowCount])
{
for (SQLRow * row in [results rowEnumerator])
{
- NSString * name = [row stringForColumn:@"foldername"];
- NSDate * lastUpdate = [NSDate dateWithTimeIntervalSince1970:[[row stringForColumn:@"last_update"] doubleValue]];
- NSInteger newItemId = [[row stringForColumn:@"folder_id"] intValue];
- NSInteger newParentId = [[row stringForColumn:@"parent_id"] intValue];
- NSInteger unreadCount = [[row stringForColumn:@"unread_count"] intValue];
- NSInteger type = [[row stringForColumn:@"type"] intValue];
- NSInteger flags = [[row stringForColumn:@"flags"] intValue];
- NSInteger nextSibling = [[row stringForColumn:@"next_sibling"] intValue];
- NSInteger firstChild = [[row stringForColumn:@"first_child"] intValue];
+ NSInteger newItemId = [[row stringForColumnAtIndex:0] intValue];
+ NSInteger newParentId = [[row stringForColumnAtIndex:1] intValue];
+ NSString * name = [row stringForColumnAtIndex:2];
+ NSInteger unreadCount = [[row stringForColumnAtIndex:3] intValue];
+ NSDate * lastUpdate = [NSDate dateWithTimeIntervalSince1970:[[row stringForColumnAtIndex:4] doubleValue]];
+ NSInteger type = [[row stringForColumnAtIndex:5] intValue];
+ NSInteger flags = [[row stringForColumnAtIndex:6] intValue];
+ NSInteger nextSibling = [[row stringForColumnAtIndex:7] intValue];
+ NSInteger firstChild = [[row stringForColumnAtIndex:8] intValue];
Folder * folder = [[[Folder alloc] initWithId:newItemId parentId:newParentId name:name type:type] autorelease];
[folder setNextSiblingId:nextSibling];
@@ -1811,17 +1812,17 @@ -(void)initFolderArray
[results release];
// Load all RSS folders and add them to the list.
- results = [sqlDatabase performQuery:@"select * from rss_folders"];
+ results = [sqlDatabase performQuery:@"select folder_id, feed_url, username, last_update_string, description, home_page from rss_folders"];
if (results && [results rowCount])
{
for (SQLRow * row in[results rowEnumerator])
{
- NSInteger folderId = [[row stringForColumn:@"folder_id"] intValue];
- NSString * descriptiontext = [row stringForColumn:@"description"];
- NSString * url = [row stringForColumn:@"feed_url"];
- NSString * linktext = [row stringForColumn:@"home_page"];
- NSString * username = [row stringForColumn:@"username"];
- NSString * lastUpdateString = [row stringForColumn:@"last_update_string"];
+ NSInteger folderId = [[row stringForColumnAtIndex:0] intValue];
+ NSString * url = [row stringForColumnAtIndex:1];
+ NSString * username = [row stringForColumnAtIndex:2];
+ NSString * lastUpdateString = [row stringForColumnAtIndex:3];
+ NSString * descriptiontext = [row stringForColumnAtIndex:4];
+ NSString * linktext = [row stringForColumnAtIndex:5];
Folder * folder = [self folderFromID:folderId];
[folder setFeedDescription:descriptiontext];
@@ -2274,13 +2275,16 @@ -(NSArray *)arrayOfArticles:(NSInteger)folderId filterString:(NSString *)filterS
Folder * folder = nil;
NSInteger unread_count = 0;
+ queryString=@"select message_id, folder_id, parent_id, read_flag, marked_flag, deleted_flag, title, sender,"
+ @" link, createddate, date, text, revised_flag, hasenclosure_flag, enclosure from messages";
+
// If folderId is zero then we're searching the entire
// database with or without a filter string.
if (folderId == 0)
{
if ([filterString isNotEqualTo:@""])
filterClause = [NSString stringWithFormat:@" where text like '%%%@%%'", filterString];
- queryString = [NSString stringWithFormat:@"select * from messages%@", filterClause];
+ queryString = [NSString stringWithFormat:@"%@%@", queryString, filterClause];
}
else
{
@@ -2294,10 +2298,9 @@ -(NSArray *)arrayOfArticles:(NSInteger)folderId filterString:(NSString *)filterS
if ([filterString isNotEqualTo:@""])
filterClause = [NSString stringWithFormat:@" and (title like '%%%@%%' or text like '%%%@%%')", filterString, filterString];
- queryString = [NSString stringWithFormat:@"select * from messages where (%@)%@", [self criteriaToSQL:tree], filterClause];
+ queryString = [NSString stringWithFormat:@"%@ where (%@)%@", queryString, [self criteriaToSQL:tree], filterClause];
}
- [[RefreshManager articlesUpdateSemaphore] lock];
// Verify we're on the right thread
[self verifyThreadSafety];
@@ -2310,22 +2313,22 @@ -(NSArray *)arrayOfArticles:(NSInteger)folderId filterString:(NSString *)filterS
for (SQLRow * row in [results rowEnumerator])
{
- article = [[Article alloc] initWithGuid:[row stringForColumn:@"message_id"]];
- [article setTitle:[row stringForColumn:@"title"]];
- [article setAuthor:[row stringForColumn:@"sender"]];
- [article setLink:[row stringForColumn:@"link"]];
- [article setEnclosure:[row stringForColumn:@"enclosure"]];
- [article setHasEnclosure:[[row stringForColumn:@"hasenclosure_flag"] intValue]];
- [article setDate:[NSDate dateWithTimeIntervalSince1970:[[row stringForColumn:@"date"] doubleValue]]];
- [article setCreatedDate:[NSDate dateWithTimeIntervalSince1970:[[row stringForColumn:@"createddate"] doubleValue]]];
- [article markRead:[[row stringForColumn:@"read_flag"] intValue]];
- [article markRevised:[[row stringForColumn:@"revised_flag"] intValue]];
- [article markFlagged:[[row stringForColumn:@"marked_flag"] intValue]];
- [article markDeleted:[[row stringForColumn:@"deleted_flag"] intValue]];
- [article setFolderId:[[row stringForColumn:@"folder_id"] intValue]];
- [article setParentId:[[row stringForColumn:@"parent_id"] intValue]];
- text = [row stringForColumn:@"text"];
+ article = [[Article alloc] initWithGuid:[row stringForColumnAtIndex:0]];
+ [article setFolderId:[[row stringForColumnAtIndex:1] intValue]];
+ [article setParentId:[[row stringForColumnAtIndex:2] intValue]];
+ [article markRead:[[row stringForColumnAtIndex:3] intValue]];
+ [article markFlagged:[[row stringForColumnAtIndex:4] intValue]];
+ [article markDeleted:[[row stringForColumnAtIndex:5] intValue]];
+ [article setTitle:[row stringForColumnAtIndex:6]];
+ [article setAuthor:[row stringForColumnAtIndex:7]];
+ [article setLink:[row stringForColumnAtIndex:8]];
+ [article setCreatedDate:[NSDate dateWithTimeIntervalSince1970:[[row stringForColumnAtIndex:9] doubleValue]]];
+ [article setDate:[NSDate dateWithTimeIntervalSince1970:[[row stringForColumnAtIndex:10] doubleValue]]];
+ text = [row stringForColumnAtIndex:11];
[article setBody:text];
+ [article markRevised:[[row stringForColumnAtIndex:12] intValue]];
+ [article setHasEnclosure:[[row stringForColumnAtIndex:13] intValue]];
+ [article setEnclosure:[row stringForColumnAtIndex:14]];
if (folder == nil || ![article isDeleted] || IsTrashFolder(folder))
[newArray addObject:article];
[folder addArticleToCache:article];
@@ -2354,7 +2357,6 @@ -(NSArray *)arrayOfArticles:(NSInteger)folderId filterString:(NSString *)filterS
// Deallocate
[results release];
- [[RefreshManager articlesUpdateSemaphore] unlock];
return newArray;
}
View
6 src/GoogleReader.m
@@ -256,7 +256,6 @@ - (void)feedRequestDone:(ASIHTTPRequest *)request
Database *db = [Database sharedDatabase];
NSInteger newArticlesFromFeed = 0;
- [[RefreshManager articlesUpdateSemaphore] lock];
// Here's where we add the articles to the database
if ([articleArray count] > 0)
@@ -287,7 +286,6 @@ - (void)feedRequestDone:(ASIHTTPRequest *)request
[db setFolderLastUpdate:[refreshedFolder itemId] lastUpdate:updateDate];
// Set the HTML homepage for this folder.
[db setFolderHomePage:[refreshedFolder itemId] newHomePage:[[[dict objectForKey:@"alternate"] objectAtIndex:0] objectForKey:@"href"]];
- [[RefreshManager articlesUpdateSemaphore] unlock];
// Add to count of new articles so far
countOfNewArticles += newArticlesFromFeed;
@@ -310,7 +308,7 @@ - (void)feedRequestDone:(ASIHTTPRequest *)request
// If this folder also requires an image refresh, add that
if ([refreshedFolder flags] & MA_FFlag_CheckForImage)
- [[RefreshManager sharedManager] performSelectorInBackground:@selector(refreshFavIcon:) withObject:refreshedFolder];
+ [[RefreshManager sharedManager] performSelectorOnMainThread:@selector(refreshFavIcon:) withObject:refreshedFolder waitUntilDone:NO];
} else { // apparently Google does not recognize the user anymore...
[aItem setStatus:NSLocalizedString(@"Error", nil)];
@@ -608,9 +606,7 @@ -(void)subscriptionsRequestDone:(ASIHTTPRequest *)request
for (Folder * f in [[NSApp delegate] folders]) {
if (IsGoogleReaderFolder(f) && ![googleFeeds containsObject:[f feedURL]])
{
- [[RefreshManager articlesUpdateSemaphore] lock];
[[Database sharedDatabase] deleteFolder:[f itemId]];
- [[RefreshManager articlesUpdateSemaphore] unlock];
}
}
View
1  src/RefreshManager.h
@@ -38,7 +38,6 @@
}
+(RefreshManager *)sharedManager;
-+ (NSRecursiveLock *)articlesUpdateSemaphore;
-(void)refreshFolderIconCacheForSubscriptions:(NSArray *)foldersArray;
//-(void)refreshSubscriptions:(NSArray *)foldersArray ignoringSubscriptionStatus:(BOOL)ignoreSubStatus;
-(void)refreshSubscriptionsAfterRefresh:(NSArray *)foldersArray ignoringSubscriptionStatus:(BOOL)ignoreSubStatus;
View
29 src/RefreshManager.m
@@ -36,7 +36,6 @@
// Singleton
static RefreshManager * _refreshManager = nil;
-static NSRecursiveLock * articlesUpdate_lock;
// Private functions
@interface RefreshManager (Private)
@@ -61,14 +60,8 @@ @implementation RefreshManager
+ (void)initialize
{
- // Initializes our multi-thread lock
- articlesUpdate_lock = [[NSRecursiveLock alloc] init];
}
-+ (NSRecursiveLock *)articlesUpdateSemaphore
-{
- return articlesUpdate_lock;
-}
/* init
* Initialise the class.
@@ -256,7 +249,7 @@ -(void)refreshFolderIconCacheForSubscriptions:(NSArray *)foldersArray
[self refreshFolderIconCacheForSubscriptions:[[Database sharedDatabase] arrayOfFolders:[folder itemId]]];
else if (IsRSSFolder(folder) || IsGoogleReaderFolder(folder))
{
- [self performSelectorInBackground:@selector(refreshFavIcon:) withObject:folder];
+ [self performSelectorOnMainThread:@selector(refreshFavIcon:) withObject:folder waitUntilDone:NO];
}
}
}
@@ -266,7 +259,6 @@ -(void)refreshFolderIconCacheForSubscriptions:(NSArray *)foldersArray
*/
-(void)refreshFavIcon:(Folder *)folder
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Do nothing if there's no homepage associated with the feed
// or if the feed already has a favicon.
@@ -276,14 +268,12 @@ -(void)refreshFavIcon:(Folder *)folder
@synchronized(db) {
[db clearFolderFlag:[folder itemId] flagToClear:MA_FFlag_CheckForImage];
};
- [pool drain];
return;
}
if (![self isRefreshingFolder:folder ofType:MA_Refresh_FavIcon])
[self pumpFolderIconRefresh:folder];
- [pool drain];
}
/* isRefreshingFolder
@@ -641,9 +631,7 @@ -(void)folderRefreshCompleted:(ASIHTTPRequest *)connector
if (responseStatusCode == 304)
{
// No modification from last check
- [[RefreshManager articlesUpdateSemaphore] lock];
[db setFolderLastUpdate:folderId lastUpdate:[NSDate date]];
- [[RefreshManager articlesUpdateSemaphore] unlock];
[self setFolderErrorFlag:folder flag:NO];
[connectorItem appendDetail:NSLocalizedString(@"Got HTTP status 304 - No news from last check", nil)];
@@ -660,7 +648,7 @@ -(void)folderRefreshCompleted:(ASIHTTPRequest *)connector
// [db setFolderLastUpdate:folderId lastUpdate:[NSDate date]];
// If this folder also requires an image refresh, add that
- if (([folder flags] & MA_FFlag_CheckForImage)) [self performSelectorInBackground:@selector(refreshFavIcon:) withObject:folder];
+ if (([folder flags] & MA_FFlag_CheckForImage)) [self performSelectorOnMainThread:@selector(refreshFavIcon:) withObject:folder waitUntilDone:NO];
}
else if (responseStatusCode == 410)
{
@@ -674,13 +662,14 @@ -(void)folderRefreshCompleted:(ASIHTTPRequest *)connector
NSData * receivedData = [connector responseData];
NSString * lastModifiedString = [[connector responseHeaders] valueForKey:@"Last-Modified"];
- [self performSelectorInBackground:@selector(finalizeFolderRefresh:) withObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ [self performSelectorOnMainThread:@selector(finalizeFolderRefresh:) withObject:[NSDictionary dictionaryWithObjectsAndKeys:
folder, @"folder",
connectorItem, @"log",
url, @"url",
receivedData, @"data",
lastModifiedString, @"lastModifiedString",
- nil]];
+ nil]
+ waitUntilDone:NO];
}
else //other HTTP response codes like 404, 403...
{
@@ -693,7 +682,6 @@ -(void)folderRefreshCompleted:(ASIHTTPRequest *)connector
-(void)finalizeFolderRefresh:(NSDictionary*)parameters;
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ZAssert(parameters!=NULL, @"Null");
Folder * folder = (Folder *)[parameters objectForKey:@"folder"];
NSInteger folderId = [folder itemId];
@@ -719,7 +707,6 @@ -(void)finalizeFolderRefresh:(NSDictionary*)parameters;
else
{
[self refreshFeed:folder fromURL:[NSURL URLWithString:redirectURL] withLog:connectorItem shouldForceRefresh:NO];
- [pool drain];
return;
}
}
@@ -760,7 +747,6 @@ -(void)finalizeFolderRefresh:(NSDictionary*)parameters;
[self setFolderErrorFlag:folder flag:YES];
[connectorItem setStatus:NSLocalizedString(@"Error parsing XML data in feed", nil)];
[newFeed release];
- [pool drain];
return;
}
@@ -845,7 +831,6 @@ -(void)finalizeFolderRefresh:(NSDictionary*)parameters;
[article release];
}
- [articlesUpdate_lock lock];
// Remember the last modified date
if (lastModifiedString != nil)
[db setFolderLastUpdateString:folderId lastUpdateString:lastModifiedString];
@@ -901,7 +886,6 @@ -(void)finalizeFolderRefresh:(NSDictionary*)parameters;
// Set the last update date for this folder.
[db setFolderLastUpdate:folderId lastUpdate:[NSDate date]];
- [articlesUpdate_lock unlock];
};
// Send status to the activity log
@@ -918,7 +902,7 @@ -(void)finalizeFolderRefresh:(NSDictionary*)parameters;
// If this folder also requires an image refresh, add that
if (([folder flags] & MA_FFlag_CheckForImage))
- [self performSelectorInBackground:@selector(refreshFavIcon:) withObject:folder];
+ [self performSelectorOnMainThread:@selector(refreshFavIcon:) withObject:folder waitUntilDone:NO];
// Add to count of new articles so far
countOfNewArticles += newArticlesFromFeed;
@@ -926,7 +910,6 @@ -(void)finalizeFolderRefresh:(NSDictionary*)parameters;
// Unread count may have changed
[[NSApp delegate] performSelectorOnMainThread:@selector(showUnreadCountOnApplicationIconAndWindowTitle) withObject:nil waitUntilDone:NO];
- [pool drain];
}
/* getRedirectURL
Please sign in to comment.
Something went wrong with that request. Please try again.