From be6af575c37b9527ca2bdf07b7b67e3b00b0a6a8 Mon Sep 17 00:00:00 2001 From: "a.chubar" Date: Tue, 31 Oct 2023 19:43:38 +0300 Subject: [PATCH] changed collection diff logic so it skips items where only primary ids changed --- tpl/macro.twig | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tpl/macro.twig b/tpl/macro.twig index 92ae6bc..e44a9a9 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -19,7 +19,7 @@ {% macro decl_struct(o, extra = '') %} {% set pkey_fields = token(o, 'table_pkey')|split(',') %} -{% set pkey = o.fields|filter(f => f.name in pkey_fields ) %} +{% set pkey = pkey_fields|filter(f => f|length > 0)|map(f => o.getField(f)) %} {%- if o.parent and has_token(o, 'POD') -%} {{Error("@POD structs can't have a parent: " ~ o.name)}} @@ -128,7 +128,12 @@ public class {{o.name}}Comparer : IComparer<{{o.name}}> { int result; - {% for f in pkey %} + {% set comparable = pkey %} + {% if comparable|length > 1 %} + {% set comparable = comparable [1:] %} + {% endif %} + + {% for f in comparable %} {% if not loop.first %} if(result == 0) {% endif %} @@ -272,14 +277,34 @@ base.SyncFields(ctx); } public void SetPrimaryFieldsChanged() + { + SetPrimaryFieldsChanged(ref this.fields_mask); + } + + static void SetPrimaryFieldsChanged(ref FieldsMask mask) { {%- for f in o.fields ~%} {%- if is_primary_field(o, f) ~%} - MetaIO.SetFieldDirty(ref fields_mask, {{loop.index0}}); + MetaIO.SetFieldDirty(ref mask, {{loop.index0}}); {%- endif -%} {%- endfor ~%} } + public bool IsContentDirty() + { + int fields_amount = {{fields_count(o)}}; + var primary_id_mask = FieldsMask.MakeClean(fields_amount); + SetPrimaryFieldsChanged(ref primary_id_mask); + for(int i = 0; i < fields_amount; i++) + { + bool is_primary_id = primary_id_mask.IsDirty(i); + if(!is_primary_id && fields_mask.IsDirty(i)) + return true; + } + + return false; + } + public void SetDirtyMask() { fields_mask = FieldsMask.MakeDirty(fields_amount: {{fields_count(o)}}); @@ -426,7 +451,7 @@ public class {{o.name}} : IRpc } else { - if(!{{_self.compare_func_name(u)}}(ref item, old)) + if(!{{_self.compare_func_name(u)}}(ref item, old) && item.IsContentDirty()) { if(changed != null) changed.Add(item);