Querying data when sending e-mail

Querying data when sending e-mail

  

Hi,

I've the following question:
I'm creating an application that is going to send about 400 e-mails in one action, with each time only one recipient in the TO-field (so 400 seperate messages). Each message contains html content that is queried from the database (up to 10000 characters), but each e-mail contains the same content.

What would be better:
- Using the id of the content record as a parameter of the e-mail and query the content in the preparation each time, or
- Query the content only once, an use the html-content as a parameter?

In the first case, I guess the query will be cached, so it won't actually access the database 250 time. In the second case, a really big text value has to be given as a parameter each time. What do you think?
Hi Lennart,

Thtat's an interesting question. Without being an expert in the issue - and subjecting myself to having someone correct me in no time - I would say that doing the query once is the way to go, since the .NET memory management will handle the fact that you have to have a long parameter several times.

Just to be sure: I'm suggesting this because I understood you're talking about having a large parameter being retrieved in an ACTION, and being used in the logic of that action only - i.e. it is not a screen parameter, nor a parameter that'll go back and forth in web requests to/from screens, or to/from web services.

As you were saying: yes, the query will be cached, but the data will always have to travel back and forth between the server and the DB, so there's your overhead - even if the DB is local, the data will still have to be passed to the ASP.Net memory space.

In the "one query" scenario, as it's all kept in the same memory space, I'd say that's the best way to go. I hope I'm not saying something barbaric :)

Let me know how this works.

Regards,

Paulo Tavares

Hi Paulo,

I think you are right about the cached query. It is of course cached on the DB side, so that would suggest performing the query once is best. The parameter containing the content then goes to an E-mail Screen (you know, the new ones in version 5.0). I do suspect that the platform internally treats an e-mail the same a normal screen. Can someone clearify that up?

I did find another bug in that convinced me to do the query in the preparation: The parameter content and the values of the TO, CC and BCC(!) fields are visible in the source of the e-mail in the action element of the form tag. I've already submitted this to Outsystems support.

Regards,
Lennart

Hi Lennart,

In the current email implementation, each email sent represents a diferent transaction and http request, and email parameters are effectively http get parameters, so please don't use very large parameters.

To overcome the content rendering performance, I suggest you define the email content inside a web block, set the cache property of the web block to 10 minutes, and the use the web block to define the email content.

Cheers,
Lucio