66from pathlib import Path
77
88from django .conf import settings
9-
109from ietf .utils import log
10+ from ietf .doc .models import Document
1111from ietf .doc .storage_utils import AlreadyExistsError , store_bytes
1212
1313
@@ -26,17 +26,42 @@ def build_from_file_content(rfc_numbers: list[int]) -> str:
2626
2727def load_rfcs_into_blobdb (numbers : list [int ]):
2828 types_to_load = settings .RFC_FILE_TYPES + ("json" ,)
29+ rfc_docs = Document .objects .filter (type = "rfc" , rfc_number__in = numbers ).values_list ("rfc_number" , flat = True )
2930 for num in numbers :
30- for ext in types_to_load :
31- fs_path = Path (settings .RFC_PATH ) / f"rfc{ num } .{ ext } "
32- if fs_path .is_file ():
33- with fs_path .open ("rb" ) as f :
31+ if num in rfc_docs :
32+ for ext in types_to_load :
33+ fs_path = Path (settings .RFC_PATH ) / f"rfc{ num } .{ ext } "
34+ if fs_path .is_file ():
35+ with fs_path .open ("rb" ) as f :
36+ bytes = f .read ()
37+ mtime = fs_path .stat ().st_mtime
38+ try :
39+ store_bytes (
40+ kind = "rfc" ,
41+ name = f"{ ext } /rfc{ num } .{ ext } " ,
42+ content = bytes ,
43+ allow_overwrite = False , # Intentionally not allowing overwrite.
44+ doc_name = f"rfc{ num } " ,
45+ doc_rev = None ,
46+ # Not setting content_type
47+ mtime = datetime .datetime .fromtimestamp (
48+ mtime , tz = datetime .UTC
49+ ),
50+ )
51+ except AlreadyExistsError as e :
52+ log .log (str (e ))
53+
54+ # store the not-prepped xml
55+ name = f"rfc{ num } .notprepped.xml"
56+ source = Path (settings .RFC_PATH ) / "prerelease" / name
57+ if source .is_file ():
58+ with open (source , "rb" ) as f :
3459 bytes = f .read ()
35- mtime = fs_path .stat ().st_mtime
60+ mtime = source .stat ().st_mtime
3661 try :
3762 store_bytes (
3863 kind = "rfc" ,
39- name = f"{ ext } /rfc { num } . { ext } " ,
64+ name = f"notprepped/ { name } " ,
4065 content = bytes ,
4166 allow_overwrite = False , # Intentionally not allowing overwrite.
4267 doc_name = f"rfc{ num } " ,
@@ -46,24 +71,7 @@ def load_rfcs_into_blobdb(numbers: list[int]):
4671 )
4772 except AlreadyExistsError as e :
4873 log .log (str (e ))
49-
50- # store the not-prepped xml
51- name = f"rfc{ num } .notprepped.xml"
52- source = Path (settings .RFC_PATH ) / "prerelease" / name
53- if source .is_file ():
54- with open (source , "rb" ) as f :
55- bytes = f .read ()
56- mtime = source .stat ().st_mtime
57- try :
58- store_bytes (
59- kind = "rfc" ,
60- name = f"notprepped/{ name } " ,
61- content = bytes ,
62- allow_overwrite = False , # Intentionally not allowing overwrite.
63- doc_name = f"rfc{ num } " ,
64- doc_rev = None ,
65- # Not setting content_type
66- mtime = datetime .datetime .fromtimestamp (mtime , tz = datetime .UTC ),
67- )
68- except AlreadyExistsError as e :
69- log .log (str (e ))
74+ else :
75+ log .log (
76+ f"Skipping loading rfc{ num } into blobdb as no matching Document exists"
77+ )
0 commit comments