Skip to content

Commit

Permalink
Remove NSDiscardable protocol for Article
Browse files Browse the repository at this point in the history
I've come to the conclusion that we'd better off rolling back commit
c520d75 which went into production with Vienna 3.9.3, as this has led to
some unpredictable behavior while the resulting memory gain is not
obvious and not worth the complication.
  • Loading branch information
barijaona committed Dec 3, 2024
1 parent 06f36e2 commit 1ca30a9
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 59 deletions.
6 changes: 0 additions & 6 deletions Vienna/Sources/Database/Database.m
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,6 @@ -(void)markArticleRead:(NSInteger)folderId guid:(NSString *)guid isRead:(BOOL)is
Folder * folder = [self folderFromID:folderId];
if (folder != nil) {
Article * article = [folder articleFromGuid:guid];
[article beginContentAccess];
if (article != nil && isRead != article.read) {
// Mark an individual article read
FMDatabaseQueue *queue = self.databaseQueue;
Expand All @@ -2347,7 +2346,6 @@ -(void)markArticleRead:(NSInteger)folderId guid:(NSString *)guid isRead:(BOOL)is
[self setFolderUnreadCount:folder adjustment:adjustment];
}
}
[article endContentAccess];
}
}

Expand Down Expand Up @@ -2428,7 +2426,6 @@ -(void)markArticleFlagged:(NSInteger)folderId guid:(NSString *)guid isFlagged:(B
Folder * folder = [self folderFromID:folderId];
if (folder != nil) {
Article * article = [folder articleFromGuid:guid];
[article beginContentAccess];
if (article != nil && isFlagged != article.flagged) {
FMDatabaseQueue *queue = self.databaseQueue;
__block BOOL success;
Expand All @@ -2444,7 +2441,6 @@ -(void)markArticleFlagged:(NSInteger)folderId guid:(NSString *)guid isFlagged:(B
[article markFlagged:isFlagged];
}
}
[article endContentAccess];
}
}

Expand Down Expand Up @@ -2474,9 +2470,7 @@ -(void)markArticleDeleted:(Article *)article isDeleted:(BOOL)isDeleted
if (folder.countOfCachedArticles > 0) {
// If we're in a smart folder, the cached article may be different.
Article * cachedArticle = [folder articleFromGuid:guid];
[cachedArticle beginContentAccess];
[cachedArticle markDeleted:isDeleted];
[cachedArticle endContentAccess];
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions Vienna/Sources/Main window/ArticleController.m
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,13 @@ -(void)refilterArrayOfArticles
NSInteger filterMode = [Preferences standardPreferences].filterMode;
for (NSInteger index = filteredArray.count - 1; index >= 0; --index) {
Article * article = filteredArray[index];
[article beginContentAccess];
if (guidOfArticleToPreserve != nil
&& article.folderId == articleToPreserve.folderId
&& [article.guid isEqualToString:guidOfArticleToPreserve]) {
guidOfArticleToPreserve = nil;
} else if ([self filterArticle:article usingMode:filterMode] == false) {
[filteredArray removeObjectAtIndex:index];
}
[article endContentAccess];
}

if (guidOfArticleToPreserve != nil) {
Expand Down Expand Up @@ -752,7 +750,6 @@ -(void)markFlaggedByArray:(NSArray *)articleArray flagged:(BOOL)flagged
-(void)innerMarkFlaggedByArray:(NSArray *)articleArray flagged:(BOOL)flagged
{
for (Article * theArticle in articleArray) {
[theArticle beginContentAccess];
Folder *myFolder = [[Database sharedManager] folderFromID:theArticle.folderId];
if (myFolder.type == VNAFolderTypeOpenReader) {
[[OpenReader sharedManager] markStarred:theArticle starredFlag:flagged];
Expand All @@ -761,7 +758,6 @@ -(void)innerMarkFlaggedByArray:(NSArray *)articleArray flagged:(BOOL)flagged
guid:theArticle.guid
isFlagged:flagged];
[theArticle markFlagged:flagged];
[theArticle endContentAccess];
}
}

Expand Down Expand Up @@ -807,7 +803,6 @@ -(void)markReadByArray:(NSArray *)articleArray readFlag:(BOOL)readFlag
-(void)innerMarkReadByArray:(NSArray *)articleArray readFlag:(BOOL)readFlag
{
for (Article * theArticle in articleArray) {
[theArticle beginContentAccess];
NSInteger folderId = theArticle.folderId;
if (theArticle.read != readFlag) {
if ([[Database sharedManager] folderFromID:folderId].type == VNAFolderTypeOpenReader) {
Expand All @@ -817,7 +812,6 @@ -(void)innerMarkReadByArray:(NSArray *)articleArray readFlag:(BOOL)readFlag
[theArticle markRead:readFlag];
}
}
[theArticle endContentAccess];
}
}

Expand Down
2 changes: 0 additions & 2 deletions Vienna/Sources/Main window/ArticleConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ - (instancetype)init
*/
-(NSString *)expandTagsOfArticle:(Article *)theArticle intoTemplate:(NSString *)theString withConditional:(BOOL)cond
{
NSAssert(theArticle.status != ArticleStatusDiscarded,
@"Attempting to access %@ with discarded elements", theArticle);
NSMutableString * newString = [NSMutableString stringWithString:SafeString(theString)];
NSUInteger tagStartIndex = 0;

Expand Down
5 changes: 2 additions & 3 deletions Vienna/Sources/Models/Article.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ typedef NS_ENUM(NSInteger, VNAArticleFieldTag) {
typedef NS_ENUM(NSInteger, ArticleStatus) {
ArticleStatusEmpty = 0,
ArticleStatusNew,
ArticleStatusUpdated,
ArticleStatusDiscarded
ArticleStatusUpdated
};

@interface Article : NSObject<NSDiscardableContent>
@interface Article : NSObject

// Accessor functions
-(instancetype _Nonnull)initWithGuid:(NSString * _Nonnull)theGuid /*NS_DESIGNATED_INITIALIZER*/;
Expand Down
29 changes: 0 additions & 29 deletions Vienna/Sources/Models/Article.m
Original file line number Diff line number Diff line change
Expand Up @@ -308,33 +308,4 @@ -(NSScriptObjectSpecifier *)objectSpecifier
return nil;
}

// MARK: - NSDiscardableContent

-(BOOL)beginContentAccess
{
return self.status != ArticleStatusDiscarded;
}

- (void)endContentAccess
{
// do nothing special,
// as we are not attempting to retrieve discarded content by ourself
// and don't manage any access count
}

-(void)discardContentIfPossible
{
self.status = ArticleStatusDiscarded;
[articleData removeObjectForKey:MA_Field_Text];
[articleData removeObjectForKey:MA_Field_Summary];
[articleData removeObjectForKey:MA_Field_Author];
[articleData removeObjectForKey:MA_Field_LastUpdate];
[articleData removeObjectForKey:MA_Field_PublicationDate];
}

- (BOOL)isContentDiscarded
{
return self.status == ArticleStatusDiscarded;
}

@end
13 changes: 0 additions & 13 deletions Vienna/Sources/Models/Folder.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ -(instancetype)initWithId:(NSInteger)newId parentId:(NSInteger)newIdParent name:
_containsBodies = NO;
_hasPassword = NO;
_cachedArticles = [NSCache new];
_cachedArticles.evictsObjectsWithDiscardedContent = NO;
_cachedArticles.delegate = self;
_cachedGuids = [NSMutableArray array];
_attributes = [NSMutableDictionary dictionary];
Expand Down Expand Up @@ -497,7 +496,6 @@ -(BOOL)createArticle:(Article *)article guidHistory:(NSArray *)guidHistory
return NO; // Article has been deleted and removed from database, so ignore
} else {
// add the article as new
[article beginContentAccess];
BOOL success = [[Database sharedManager] addArticle:article toFolder:self.itemId];
if (success) {
article.status = ArticleStatusNew;
Expand All @@ -510,17 +508,14 @@ -(BOOL)createArticle:(Article *)article guidHistory:(NSArray *)guidHistory
adjustment = 1;
}
} else {
[article endContentAccess];
return NO;
}
[article endContentAccess];
}
} else if (existingArticle.deleted) {
return NO;
} else if (![[Preferences standardPreferences] boolForKey:MAPref_CheckForUpdatedArticles]) {
return NO;
} else {
[existingArticle beginContentAccess];
BOOL success = [[Database sharedManager] updateArticle:existingArticle ofFolder:self.itemId withArticle:article];
if (success) {
// Update folder unread count if necessary
Expand All @@ -533,10 +528,8 @@ -(BOOL)createArticle:(Article *)article guidHistory:(NSArray *)guidHistory
}
latestFetchCount++;
} else {
[existingArticle endContentAccess];
return NO;
}
[existingArticle endContentAccess];
}

// Fix unread count on parent folders and Database manager
Expand Down Expand Up @@ -611,14 +604,12 @@ -(void)ensureCache
@synchronized(self) {
NSArray * myArray = [[Database sharedManager] minimalCacheForFolder:self.itemId];
for (Article * myArticle in myArray) {
[myArticle beginContentAccess];
NSString * guid = myArticle.guid;
myArticle.status = [self retrieveKnownStatusForGuid:guid];
[self.cachedArticles setObject:myArticle forKey:guid];
if (![self.cachedGuids containsObject:guid]) {
[self.cachedGuids addObject:guid];
}
[myArticle endContentAccess];
}
self.isCached = YES;
// Note that this only builds a minimal cache, so we cannot set the containsBodies flag
Expand Down Expand Up @@ -671,9 +662,7 @@ -(void)resetArticleStatuses
if (article &&
(article.status == ArticleStatusNew || article.status == ArticleStatusUpdated))
{
[article beginContentAccess];
article.status = ArticleStatusEmpty;
[article endContentAccess];
count--;
if (count == 0) {
break;
Expand Down Expand Up @@ -766,12 +755,10 @@ -(void)resetArticleStatuses
if (self.type == VNAFolderTypeRSS || self.type == VNAFolderTypeOpenReader) {
[self.cachedGuids removeAllObjects];
for (Article * article in articles) {
[article beginContentAccess];
NSString * guid = article.guid;
article.status = [self retrieveKnownStatusForGuid:guid];
[self.cachedArticles setObject:article forKey:guid];
[self.cachedGuids addObject:guid];
[article endContentAccess];
}
self.isCached = YES;
self.containsBodies = YES;
Expand Down

0 comments on commit 1ca30a9

Please sign in to comment.