Don't delete an index if the sizes don't match

This commit is contained in:
Daoud Clarke 2022-12-27 10:52:46 +00:00
parent bb8a36a612
commit c69108cfcc
2 changed files with 3 additions and 8 deletions

View file

@ -4,7 +4,7 @@ from mwmbl.crawler.app import get_batches_for_date
from mwmbl.database import Database
from mwmbl.indexer.indexdb import BatchInfo, BatchStatus, IndexDatabase
DAYS = 20
DAYS = 66
def run():

View file

@ -40,14 +40,9 @@ def run():
try:
existing_index = TinyIndex(item_factory=Document, index_path=index_path)
if existing_index.page_size != PAGE_SIZE or existing_index.num_pages != args.num_pages:
print(f"Existing index page sizes ({existing_index.page_size}) and number of pages "
f"({existing_index.num_pages}) does not match - removing.")
os.remove(index_path)
existing_index = None
raise ValueError(f"Existing index page sizes ({existing_index.page_size}) or number of pages "
f"({existing_index.num_pages}) do not match")
except FileNotFoundError:
existing_index = None
if existing_index is None:
print("Creating a new index")
TinyIndex.create(item_factory=Document, index_path=index_path, num_pages=args.num_pages, page_size=PAGE_SIZE)