11# Generated by Django 5.2.8 on 2025-12-19 09:37
2+ from concurrent .futures import ThreadPoolExecutor
23
34import uuid_utils .compat
45from django .db import migrations , models
6+ from django .db .models import QuerySet
57
68from knowledge .models import Knowledge
79
810
9- def resource_mapping (apps , schema_editor ):
10- from system_manage .models .resource_mapping import ResourceMapping
11+ def get_initialization_resource_mapping ():
1112 from django .db .models import QuerySet
1213 from application .flow .tools import get_workflow_resource , get_node_handle_callback , \
1314 get_instance_resource
@@ -28,7 +29,7 @@ def resource_mapping(apps, schema_editor):
2829 resource_mapping_list += workflow_mapping
2930 resource_mapping_list += instance_mapping
3031 except :
31- continue
32+ pass
3233 knowledge_ids = list (Knowledge .objects .values_list ('id' , flat = True ))
3334 for knowledge_id in knowledge_ids :
3435 try :
@@ -46,8 +47,17 @@ def resource_mapping(apps, schema_editor):
4647
4748 resource_mapping_list += instance_mapping
4849 except :
49- continue
50- QuerySet (ResourceMapping ).bulk_create (resource_mapping_list )
50+ pass
51+
52+ return resource_mapping_list
53+
54+
55+ def resource_mapping (apps , schema_editor ):
56+ from system_manage .models .resource_mapping import ResourceMapping
57+ with ThreadPoolExecutor (max_workers = 3 ) as executor :
58+ future = executor .submit (get_initialization_resource_mapping )
59+ resource_mapping_list = future .result ()
60+ QuerySet (ResourceMapping ).bulk_create (resource_mapping_list )
5161
5262
5363class Migration (migrations .Migration ):
@@ -79,5 +89,5 @@ class Migration(migrations.Migration):
7989 'db_table' : 'resource_mapping' ,
8090 },
8191 ),
82- migrations .RunPython (resource_mapping )
92+ migrations .RunPython (resource_mapping , atomic = False )
8393 ]
0 commit comments