- optimization: convert all uses of 'async for' to use iterator directly instead of converting to list to avoid unbounded size lists - additional cursor.to_list() to async for conversions for stats computation, simply crawlconfigs stats computation --------- Co-authored-by: Tessa Walsh <tessa@bitarchivist.net>
		
			
				
	
	
		
			33 lines
		
	
	
		
			1004 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1004 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| """
 | |
| Migration 0008 - Precomputing crawl file stats
 | |
| """
 | |
| from btrixcloud.crawls import recompute_crawl_file_count_and_size
 | |
| from btrixcloud.migrations import BaseMigration
 | |
| 
 | |
| 
 | |
| MIGRATION_VERSION = "0008"
 | |
| 
 | |
| 
 | |
| class Migration(BaseMigration):
 | |
|     """Migration class."""
 | |
| 
 | |
|     def __init__(self, mdb, migration_version=MIGRATION_VERSION):
 | |
|         super().__init__(mdb, migration_version)
 | |
| 
 | |
|     async def migrate_up(self):
 | |
|         """Perform migration up.
 | |
| 
 | |
|         Add data on crawl file count and size to database that was previously
 | |
|         dynamically generated in the API endpoints.
 | |
|         """
 | |
|         # pylint: disable=duplicate-code
 | |
|         crawls = self.mdb["crawls"]
 | |
| 
 | |
|         async for crawl in crawls.find({}):
 | |
|             crawl_id = crawl["_id"]
 | |
|             try:
 | |
|                 await recompute_crawl_file_count_and_size(crawls, crawl_id)
 | |
|             # pylint: disable=broad-exception-caught
 | |
|             except Exception as err:
 | |
|                 print(f"Unable to update crawl {crawl_id}: {err}", flush=True)
 |