{"id":225,"date":"2019-11-01T13:38:16","date_gmt":"2019-11-01T13:38:16","guid":{"rendered":"https:\/\/sdf-docs.mansystems.com\/docs\/acr-rules\/performance\/loop-violations\/"},"modified":"2020-07-08T14:35:30","modified_gmt":"2020-07-08T14:35:30","slug":"commitinloop","status":"publish","type":"docs","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/performance\/commitinloop","title":{"rendered":"Commits should take place outside of a loop"},"content":{"rendered":"\n<p>Introduced in version 1.4 (3 February 2020)<\/p>\n\n\n\n<p>A loop can potentially be executed hundreds or thousands of times. Therefore it is preferable to avoid doing long-running actions in a loop.<\/p>\n\n\n\n<p>Commits\/deletes can often be placed after the loop, by creating a commit-list before the loop, changing without commit, adding changed\/deleted items inside the loop and committing the commit-list at once after the loop. This saves a lot of database action.<\/p>\n\n\n\n<p><strong>Noncompliant microflow:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"691\" height=\"303\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2020\/02\/image-1.png\" alt=\"\" class=\"wp-image-1143\" srcset=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2020\/02\/image-1.png 691w, https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2020\/02\/image-1-480x210.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 691px, 100vw\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Compliant example:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"934\" height=\"300\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2020\/02\/image.png\" alt=\"\" class=\"wp-image-1142\" srcset=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2020\/02\/image.png 934w, https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2020\/02\/image-480x154.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 934px, 100vw\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"featured_media":0,"parent":95,"menu_order":2,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-225","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/225"}],"collection":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225"}],"version-history":[{"count":8,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/225\/revisions"}],"predecessor-version":[{"id":1151,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/225\/revisions\/1151"}],"up":[{"embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/95"}],"next":[{"title":"Dropdown reference selectors should be used sparingly","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/performance\/referenceselectoramount","href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/1270"}],"prev":[{"title":"Commit entities in the same order in different microflows to prevent deadlock","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/performance\/projectdeadlock","href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/1503"}],"wp:attachment":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}