mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-11-10 16:46:40 -05:00
Chore: Minor migration optimization for workflow titles (#11197)
* Makes the migration just a little more efficient * Do it in batches, just in case * Fixes the model klass name
This commit is contained in:
parent
48d21da13b
commit
cd81f750b4
@ -3,7 +3,6 @@ import logging
|
|||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db import transaction
|
|
||||||
|
|
||||||
from documents.templating.utils import convert_format_str_to_template_format
|
from documents.templating.utils import convert_format_str_to_template_format
|
||||||
|
|
||||||
@ -11,21 +10,34 @@ logger = logging.getLogger("paperless.migrations")
|
|||||||
|
|
||||||
|
|
||||||
def convert_from_format_to_template(apps, schema_editor):
|
def convert_from_format_to_template(apps, schema_editor):
|
||||||
WorkflowActions = apps.get_model("documents", "WorkflowAction")
|
WorkflowAction = apps.get_model("documents", "WorkflowAction")
|
||||||
|
|
||||||
with transaction.atomic():
|
batch_size = 500
|
||||||
for WorkflowAction in WorkflowActions.objects.all():
|
actions_to_update = []
|
||||||
if not WorkflowAction.assign_title:
|
|
||||||
continue
|
queryset = (
|
||||||
WorkflowAction.assign_title = convert_format_str_to_template_format(
|
WorkflowAction.objects.filter(assign_title__isnull=False)
|
||||||
WorkflowAction.assign_title,
|
.exclude(assign_title="")
|
||||||
|
.only("id", "assign_title")
|
||||||
|
)
|
||||||
|
|
||||||
|
for action in queryset:
|
||||||
|
action.assign_title = convert_format_str_to_template_format(
|
||||||
|
action.assign_title,
|
||||||
)
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Converted WorkflowAction id %d title to template format: %s",
|
"Converted WorkflowAction id %d title to template format: %s",
|
||||||
WorkflowAction.id,
|
action.id,
|
||||||
WorkflowAction.assign_title,
|
action.assign_title,
|
||||||
|
)
|
||||||
|
actions_to_update.append(action)
|
||||||
|
|
||||||
|
if actions_to_update:
|
||||||
|
WorkflowAction.objects.bulk_update(
|
||||||
|
actions_to_update,
|
||||||
|
["assign_title"],
|
||||||
|
batch_size=batch_size,
|
||||||
)
|
)
|
||||||
WorkflowAction.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user