@@ -33,38 +33,30 @@ def purge_cache_for_paper(paper_id:str, old_cats:Optional[str]=None):
33
33
purge_fastly_keys (keys )
34
34
return
35
35
36
- def _get_category_and_date (arxiv_id :Identifier )-> Tuple [str , date ]:
36
+ def _get_category_and_date (arxiv_id :Identifier )-> Tuple [str , Optional [ date ] ]:
37
37
"""fetches the current categories for a paper as well as the last date it had announced changes to determine if it belongs in recent or new page
38
38
extra days were added to accomidate for weekends and holidays,
39
39
these will occasionally purge new and recent papers more than is needed, but better to over clear than underclear
40
40
"""
41
41
meta = aliased (Metadata )
42
42
up = aliased (Updates )
43
- sub = (
44
- Session .query (
45
- meta .abs_categories ,
46
- meta .document_id
47
- )
48
- .filter (meta .paper_id == arxiv_id .id )
49
- .filter (meta .is_current == 1 )
50
- .subquery ()
51
- )
52
43
53
44
result = (
54
45
Session .query (
55
- sub . c . abs_categories ,
56
- func .max (up .date )
46
+ meta . abs_categories ,
47
+ func .max (up .date )
57
48
)
58
- .join (up , up .document_id == sub . c . document_id )
59
- .group_by ( sub . c . document_id )
60
- .filter (up . action != "absonly" )
49
+ .outerjoin (up , ( up .document_id == meta . document_id ) & ( up . action != "absonly" )) #left join
50
+ .filter ( meta . paper_id == arxiv_id . id )
51
+ .filter (meta . is_current == 1 )
61
52
.first ()
62
53
)
63
- if not result :
64
- raise IdentifierException (f'paper id does not exist: { arxiv_id .id } ' )
65
-
66
54
new_cats : str = result [0 ]
67
- recent_date : date = result [1 ]
55
+ recent_date : Optional [date ] = result [1 ] #Papers that havent been changed since 2007 may not be in updates table
56
+
57
+ if not new_cats :
58
+ raise IdentifierException (f'paper id not found: { arxiv_id .id } ' )
59
+
68
60
return new_cats , recent_date
69
61
70
62
def _purge_category_change (arxiv_id :Identifier , old_cats :Optional [str ]= None )-> List [str ]:
@@ -80,10 +72,11 @@ def _purge_category_change(arxiv_id:Identifier, old_cats:Optional[str]=None )->
80
72
today = date .today ()
81
73
new = False
82
74
recent = False
83
- if today - timedelta (days = 3 ) <= recent_date : #farthest away a date on the new page would likely be
84
- new = True
85
- if today - timedelta (days = 7 ) <= recent_date :
86
- recent = True
75
+ if recent_date :
76
+ if today - timedelta (days = 3 ) <= recent_date : #farthest away a date on the new page would likely be
77
+ new = True
78
+ if today - timedelta (days = 7 ) <= recent_date :
79
+ recent = True
87
80
88
81
groups , archives , cats = get_all_cats_from_string (new_cats , True )
89
82
new_archive_ids = {arch .id for arch in archives }
0 commit comments