/
AbstractRefreshManager.m
86 lines (79 loc) · 2.6 KB
/
AbstractRefreshManager.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// AbstractRefreshManager.m
// inspire
//
// Created by Yuji on 2015/08/31.
//
//
#import "AbstractRefreshManager.h"
#import "Article.h"
#import "JournalEntry.h"
#import "DumbOperation.h"
#import "ArxivMetadataFetchOperation.h"
#import "LoadAbstractDOIOperation.h"
@implementation AbstractRefreshManager
{
NSMutableArray*articlesRecentlyRefreshed;
}
+(AbstractRefreshManager*)sharedAbstractRefreshManager
{
static AbstractRefreshManager*x=nil;
if(!x){
x=[[AbstractRefreshManager alloc]init];
}
return x;
}
-(void)refreshAbstractOfArticle:(Article*)a whenRefreshed:(void(^)(Article*refreshedArticle))whenDoneBlock
{
if(![[OperationQueues arxivQueue] isOnline]){
return;
}
if(a.abstract && ![a.abstract isEqualToString:@""]){
return;
}
// prevent lots of access to the same article when the abstract loading fails
{
if(!articlesRecentlyRefreshed){
articlesRecentlyRefreshed=[NSMutableArray array];
}
if([articlesRecentlyRefreshed count]>1000){
articlesRecentlyRefreshed=[NSMutableArray array];
}
if([articlesRecentlyRefreshed containsObject:a]){
return;
}
[articlesRecentlyRefreshed addObject:a];
}
if(a.eprint && ![a.eprint isEqualToString:@""]){
NSOperation*op=[[ArxivMetadataFetchOperation alloc] initWithArticle:a];
if(whenDoneBlock) {
[op setCompletionBlock:^{
dispatch_async(dispatch_get_main_queue(), ^{
whenDoneBlock(a);
});
}];
}
NSLog(@"actually prefetching abstract of: %@",a.eprint);
[[OperationQueues arxivQueue] addOperation:op];
}else if(a.doi && ![a.doi isEqualToString:@""]){
if(!a.doi || [a.doi isEqualToString:@""]) return;
NSArray* knownJournals=[[NSUserDefaults standardUserDefaults] arrayForKey:@"KnownJournals"];
if(![knownJournals containsObject:a.journal.name]){
return;
}
NSOperation*op=[[LoadAbstractDOIOperation alloc] initWithArticle:a];
if(whenDoneBlock) {
[op setCompletionBlock:^{
dispatch_async(dispatch_get_main_queue(), ^{
whenDoneBlock(a);
});
}];
}
[[OperationQueues spiresQueue] addOperation:op];
}
if(!a.texKey || [a.texKey isEqualToString:@""]){
// [[DumbOperationQueue spiresQueue] addOperation:[[BatchBibQueryOperation alloc]initWithArray:[NSArray arrayWithObject:a]]];
// [self getBibEntriesWithoutDisplay:self];
}
}
@end