Check condition in expression or on after fetch?
Question
Application Type
Mobile

I've a list in which I have to check a condition on the retrieved records (this has to be done after getting the values from the db). The outcome of this condition is basically text. Is it better to create a new text variable and assign it on the after fetch, or place the if inside the expression?

I'm assuming putting it on after fetch consumes more memory but saves processing time. But I am purely speculating.

Hello Tony,

I think it's best to include an if inside the expression.

Regards,

Jorge Rodrigues

Could you help me understand why?

Hello Tony,

Yes, it would be better to pull all the data from database and then put your logic to verify the conditions on that set of data. Please refer this link in support of this.

https://success.outsystems.com/Documentation/11/Developing_an_Application/Implement_Application_Logic/Screen_and_Block_Lifecycle_Events?

https://success.outsystems.com/Documentation/11/Developing_an_Application/Use_Data/Query_Data/Implement_asynchronous_data_fetching_using_Aggregates?

Thanks & Kind Regards,

Sachin

I am not sure if this answers my question :(

Have you gone through with the above 2 links completely?

Hi Tony,

do you mean that this text you want to show, is determined based on the list data?  Is there one piece of text per record, or is it some sort of total information describing the list as a whole ?

So let's assume it's a piece of text per record, that depends on the data in that single record.  It's not about filtering things out right, you are showing all records, this condition is not to determine if a record is in or out ??

If so, both alternatives you propose are running on the device, not the server, and I don't think it really matters very much for performance (that's what you worry about, right ?)  As long as you make good use of pagination (i think this is with onScrollEnding in mobile, but I'm not sure) this condition you  check will only be for maybe 50 records at a time.

Can you explain why you don't want to execute the condition while retrieving data from the database or while still being on the server (in an fetch action) ??  If the condition is for determining if a record is in or out, that is definitely something I would look at doing server side, otherwise you are bringing back whole unused records to the device, but also when not, let's say your piece of text depends on the value of several large attributes, determining it on the server, will reduce the amount of data that has to be brought back to the device.

Dorine

Summarizing it is:
For every record, there is a field, lets call it number. If this field is the same on the previous record, i have to add the text "repeated" at the end of my expression. I was wondering if I create a boolean IsRepeated or if i just do the check in the expression inside the list itself

Ok,

so you basically have 3 options :

  • add boolean in your fetch output and loop over the list at end of fetch (server side) determining this value for each row (not possible if you have screen aggregate instead of data action)
  • add boolean in your aggregate or fetch output that is defaulted to for example false, have an onAfterFetch and loop over the list in the onAfterFetch (device side) determining where it should be set to true
  • no boolean needed, no (explicit) loop needed, you compare in an expression (device side) with the value in the previous row

I personally prefer keeping my client side code as simple and clean as possible, so I would prefer option 1.  Option 3 looks like adding the least clutter / moving parts, but I don't like hiding logic in expressions and I don't like indexing into other rows (which you would need to do to compare with previous row)

So it is a matter of taste, as long as you don't fetch too many rows in one go, performance doesn't really come into it (except if you know your users have old devices, in that case, the more you can run on server, the better)

Dorine

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.