- 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>
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"""
 | 
						|
Migration 0013 - Copy config name to crawls
 | 
						|
"""
 | 
						|
from btrixcloud.migrations import BaseMigration
 | 
						|
 | 
						|
 | 
						|
MIGRATION_VERSION = "0013"
 | 
						|
 | 
						|
 | 
						|
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.
 | 
						|
 | 
						|
        Copy crawl config names to associated crawls.
 | 
						|
        """
 | 
						|
        # pylint: disable=duplicate-code
 | 
						|
        crawls = self.mdb["crawls"]
 | 
						|
        crawl_configs = self.mdb["crawl_configs"]
 | 
						|
 | 
						|
        async for config in crawl_configs.find({"inactive": {"$ne": True}}):
 | 
						|
            config_id = config["_id"]
 | 
						|
            try:
 | 
						|
                if not config.get("name"):
 | 
						|
                    continue
 | 
						|
                await crawls.update_many(
 | 
						|
                    {"cid": config_id}, {"$set": {"name": config.get("name")}}
 | 
						|
                )
 | 
						|
            # pylint: disable=broad-exception-caught
 | 
						|
            except Exception as err:
 | 
						|
                print(
 | 
						|
                    f"Unable to set name for crawls from with config {config_id}: {err}",
 | 
						|
                    flush=True,
 | 
						|
                )
 |