Skip to content

Commit

Permalink
Update performance-modeling.md (#513)
Browse files Browse the repository at this point in the history
* Update performance-modeling.md

We have updated the calculated fields section to now reflect the new CDS calculated element capabilities.
@renejeglinsky we do not know how to properly link other Capire pages within the markup, so I pasted two absolute links in the text. Can you please replace them with the proper internal link syntax?

* Apply suggestions from code review

* Update performance-modeling.md

Adapted feedback from Rene

---------

Co-authored-by: René Jeglinsky <[email protected]>
  • Loading branch information
nkaputnik and renejeglinsky authored Nov 6, 2023
1 parent f516856 commit 507cda4
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions advanced/performance-modeling.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ Typical examples of calculated fields are:
The following steps show you which option takes precedence over another. Use options one/two as the preferred way and three/four as fallback.

1. Do the calculation on the UI with help of field controls or dedicated custom controls. This applies to all kinds of **String concatenation** and **Formatting**.
2. Pre-calculate on *write* with help of an event handler.
3. Some Calculated Fields are dynamic in nature. Do those calculations on the database layer. For example _kanban_ (scheduling system for lean manufacturing), there you typically have dynamic live calculations.
2. Pre-calculate using CDS [on write](../cds/cdl#on-write) calculated fields.
3. Some calculations are dynamic in nature. If possible, use CDS [on read](../cds/cdl#on-read) calculated fields.
4. As a **very last resort**, use event handlers on *read*.

Hints:
Expand Down Expand Up @@ -312,35 +312,15 @@ entity OrdersItemsView as projection on OrdersItems {
::: code-group
```cds [schema.cds]
extend my.OrdersItems with {
itemCategory: String enum{ Small; Medium; Large;};
// fill itemCategory at runtime in service.js
category: String = case
when quantity > 500 then 'Large'
when quantity > 100 then 'Medium'
else 'Small'
end stored;
}
```
:::

::: code-group
```js [service.js]
...
// fill itemCategory at runtime
this.before (['CREATE', 'UPDATE'], 'my.OrdersItems', async req => {
if (req.data.quantity > 500) {req.data.itemCategory = 'Large'}
else if (req.data.quantity > 100) {req.data.itemCategory = 'Medium'}
else {req.data.itemCategory = 'Small'}
})
...
```
:::

New `OrdersItemsView` without case statement:

::: code-group
```cds [service.cds]
entity OrdersItemsView as projection on OrdersItems {
*,
itemCategory as category
};
```
:::

## Compositions vs Associations
From the performance perspective there are some cases, where you have to check out carefully if the general semantic rules of compositions vs associations should be applied.
Expand Down

0 comments on commit 507cda4

Please sign in to comment.