Commit a109163
authored
Optimize condition order to avoid unnecessary method calls in AutoMapper (#286)
This PR reorders the generated condition checks in the generate() method
to prioritize the customCondition() check before other standard
conditions.
In the generated mapper code, this change allows custom condition to
occur earlier. As a result, potentially heavy methods, such as those
that may trigger database queries are not executed if the custom
condition fails.
Before:
```php
if (isAllowedAttribute(...) && groupsCheck(...) && customCondition(...)) { // DB hit
$result->someProperty = $value->someMethod(); // DB hit
}
```
After:
```php
if (customCondition(...) && isAllowedAttribute(...) && groupsCheck(...)) {
$result->someProperty = $value->someMethod(); // DB hit only if needed
}
```2 files changed
+5
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
64 | | - | |
65 | 64 | | |
66 | 65 | | |
67 | 66 | | |
| |||
0 commit comments