Skip to content

Commit 054fd0a

Browse files
committed
[IMP] convert_binary_field_to_attachment: log progress
This operation can be long. Part-of: #42
1 parent 78212ce commit 054fd0a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/util/fields.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def make_index_name(table_name, column_name):
3232
from .exceptions import SleepyDeveloperError
3333
from .helpers import _dashboard_actions, _validate_model, table_of_model
3434
from .inherit import for_each_inherit
35-
from .misc import SelfPrintEvalContext, version_gte
35+
from .misc import SelfPrintEvalContext, log_progress, version_gte
3636
from .orm import env
3737
from .pg import (
3838
alter_column_type,
@@ -671,6 +671,9 @@ def convert_binary_field_to_attachment(cr, model, field, encoded=True, name_fiel
671671
field,
672672
)
673673

674+
cr.execute(format_query(cr, "SELECT count(*) FROM {} WHERE {} IS NOT NULL", table, field))
675+
[count] = cr.fetchone()
676+
674677
A = env(cr)["ir.attachment"]
675678
iter_cur = cr._cnx.cursor("fetch_binary")
676679
iter_cur.itersize = 1
@@ -683,7 +686,8 @@ def convert_binary_field_to_attachment(cr, model, field, encoded=True, name_fiel
683686
table=table,
684687
)
685688
)
686-
for rid, data, name in iter_cur:
689+
logger = _logger.getChild("convert_binary_field_to_attachment")
690+
for rid, data, name in log_progress(iter_cur, logger=logger, qualifier="rows", size=count):
687691
# we can't save create the attachment with res_model & res_id as it will fail computing
688692
# `res_name` field for non-loaded models. Store it naked and change it via SQL after.
689693
data = bytes(data) # noqa: PLW2901

0 commit comments

Comments
 (0)