Forums de discussion

Single database table hit for multiple portlets

Alex Man, modifié il y a 7 années.

Single database table hit for multiple portlets

Junior Member Publications: 70 Date d'inscription: 08/02/16 Publications récentes
I have created a dashboard page which have 7 portlets. The portlets will display details based on the url param called taxId. The working logic is as given below:
I am having a url with a uel param taxId, taxId value will be different for difeerent tax accounts, some examples are given below

http://localhost:8080/dashboard?taxId=51482
http://localhost:8080/dashboard?taxId=14526
http://localhost:8080/dashboard?taxId=75864
http://localhost:8080/dashboard?taxId=14802

Step1: for getting details I need to hit the tax table with the taxId which I have got from the url. From the tax table I will get companyId.
Step2: Each portlets need the companyId for displaying different information's
Step3: The companyId fetching logic is common accros all the 7 portlets.

So whenever user hits a url all the 7 portlets will perform the same logic hitting the database seven times for getting the companyId.

I would like to know whether there is any other way in which it will hit once to the tax table and fetch the companyId and give it to all the 7 portlets rather than hitting 7 times through 7 portlets

Can anyone please tell me some solution for this
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Single database table hit for multiple portlets

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
You're overthinking it.

Liferay supports caching of returned DB results in ehcache, default will be 10k records (make sure you set the cache-enabled attribute on the entity). So even if there are 7 individual portlets invoking SB code to pull a tax record using a tax id, this will actually be just one DB query followed by 6 cache hits.

So SB will handle this for you, you just have to focus on building out the fetch logic.






Come meet me at the LSNA!
Alex Man, modifié il y a 7 années.

RE: Single database table hit for multiple portlets

Junior Member Publications: 70 Date d'inscription: 08/02/16 Publications récentes
David H Nebinger:
You're overthinking it.

Liferay supports caching of returned DB results in ehcache, default will be 10k records (make sure you set the cache-enabled attribute on the entity). So even if there are 7 individual portlets invoking SB code to pull a tax record using a tax id, this will actually be just one DB query followed by 6 cache hits.

So SB will handle this for you, you just have to focus on building out the fetch logic.


Thanks for the reply, I am using Service Builder, the problem lies here is that the tax table data is been populated from a different application, so if we turn on the cache-enabled do we get the newly inserted data.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Single database table hit for multiple portlets (Réponse)

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
Alex Man:
Thanks for the reply, I am using Service Builder, the problem lies here is that the tax table data is been populated from a different application, so if we turn on the cache-enabled do we get the newly inserted data.


Well then you're kind of stuck. You have to query 7 times since you won't know if the external app updated values mid way through.

I'm guessing, however, that you have "static" data such as companyId and "volatile" data such as tax collected but you've put them into the same table. If you could separate your static data, that you could enable caching on that and disable for the volatile data.










Come meet me at the LSNA!
thumbnail
Samuel Kong, modifié il y a 7 années.

RE: Single database table hit for multiple portlets

Liferay Legend Publications: 1902 Date d'inscription: 10/03/08 Publications récentes
If you're using Service Builder, the query will be cached and it won't t hit the db 7 times.