Avoid usage of Rec.Count() if possible #722
christophstuber
started this conversation in
New Rule
Replies: 1 comment
-
@christophstuber, this idea was long overdue where I've today decided to create the rule for this. I've ended up splitsing this into two separate rules. The reason for this, is that I believe the first one (LC0081) could be set as a warning for all projects, where the second one (LC0082) is a balance between performance and readability of the code. In this way it's more flexible on which of these rules want to be enforced.
Which both is now available in the v0.31.4 (pre)release version of the LinterCop. Thank you for creating this idea, especially the part on the Rec.Find('-') with Rec.Next(), that is a nice catch. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Count can be one of the most expensive database operations on large tables. I often see examples like this in code:
Checking for no records:
Should be replaced by:
Checking for any records:
Becomes:
Checking for exactly one record:
Refering to https://vjeko.com/2017/03/08/the-if-count-1-conundrum/
Checking for more than one record:
Beta Was this translation helpful? Give feedback.
All reactions