OCLps Example
No edit summary
No edit summary
Line 4: Line 4:
[[File:OCLps_Example_Image.png|frameless|397x397px]]  
[[File:OCLps_Example_Image.png|frameless|397x397px]]  


For example, this model shows a comment section for an article:
This model shows a comment section for an article, stored in the database, as one table for the article, one table for the SysUsers, and one table for the comments. We select from the comments an article that points to the self. Because we want to increase the performance, we must decide whether we're going to show a list of articles or one article to load into the memory and sum up. 


It is stored in the database as one table for the article, one table for the SysUsers, and one table for the comments. This is like two multi-links with one in one end and many here.
________________
 
The expression for that is: 
 
(image)
 
This is done here so that the SysUser won't have tens of thousands of comments. We select from the comments an article that, in this case, points to the self. We take the first comment because this is a collection, but we know for a fact that this will be the only one. Looking at how we can increase the performance or the performance problems that we could have here, we must decide whether we're going to show a list of articles or one article. We need to load it into memory and sum it up. If we were to use the article view which shows the content, we would want to show how many likes this article has gotten and the list of comments which could also be a list of articles. We still want to show the like count and we have three different implementations of how to show the like count. One way would be to say: 
 
(image)


and select the likes and then show the number. That would require the system to load every comment object into memory and then filter out the ones that have like, that are not null, and see how many they are.  
and select the likes and then show the number. That would require the system to load every comment object into memory and then filter out the ones that have like, that are not null, and see how many they are.  


We decide to use the PSEval value. We want an integer. We use the PSVAL value and we say self.comments - this is basically the same as it would be in the OCL. PS (persistent storage) says we can do this in SQL and not load the objects. We take the comments, select the ones that are liked and take the size of it. In this case, we are also subscribing to the article which means that this would be re-evaluated if the article changes. 
________________
 
This will work well to show how many likes you have. If the user likes or unlikes, this value would not change.


We will use PSVAL to get all the comments for this article into memory, but only the ones that have like on them. It would still load objects, but not all of them, only the liked ones up to 9,999 in this case, and then we would take the size of that. By loading the objects, we can take this size here after we have loaded the objects.  
We decide to use the PSEval value and we want an integer. We say self.comments - this is basically the same as it would be in the OCL. We take the comments, select the ones that are liked and take the size of it. In this case, we are also subscribing to the article which means that this would be re-evaluated if the article changes. This will work well to show how many likes exist. If the user likes or unlikes, this value would not change.We will use PSVAL to get all the comments for this article into memory, but only the ones that have like on them. It would still load objects, but not all of them, only the liked ones up to 9,999 in this case, and then we would take the size of that. By loading the objects, we can take this size here after we have loaded the objects.


Another alternative would be to combine OCLPS and PSEval with OCL. We first pick out the comment the user has made. Then we find all the comments and all the objects that have liked on it, except my comment object. and sum these up. We load all the objects except my own objects, and we add my own comment - liked status - manually.   
Another alternative would be to combine OCLPS and PSEval with OCL. We first pick out the comment the user has made. Then we find all the comments and all the objects that have liked on it, except my comment object. and sum these up. We load all the objects except my own objects, and we add my own comment - liked status - manually.   


This part will be executed in OCLPS   
This part will be executed in OCLPS:  


(insert image)   
(insert image)   


and this part will be in OCL   
and this part will be in OCL:  


(image).   
(image).   


The next variant would be to have this as an integer. Now, this should be the PSEval value. We have the integer and calculate the value of every comment except mine. In OCL, which is auto-subscribed, we calculate the liked form for only my comment.  
The next variant would be to have this as an integer. We calculate the value of every comment except mine. In OCL, which is auto-subscribed, we calculate the liked form for only my comment.
 
The effect of this will be that the UI will update when I like or unlike the article, but if someone else does it, it won't update until my session reloads. It will delay because it will only reload when this value is needed the next time. It's slightly off, but I don't think anyone will notice and it's a huge performance boost.
 
Paragraph 2: To show how many likes an article has, three different implementations are presented. One of the implementations is to use the PSVAL value to calculate the number of comments that are liked, without loading all the objects. This is done by selecting the comments, taking the ones that are liked, and determining the size of the selection. By loading only the objects that have been liked, performance is improved.
 
Paragraph 3: Another implementation is to combine OCLPS and PSEval with OCL. In this approach, the UI updates when the user likes or unlikes, but not when someone else does it. This slight delay is a performance boost and is unlikely to be noticed by users. By using OCLPS, the system loads all the comments except the user's own comments that have been liked and manually adds the user's own comment-liked status. The calculation of the liked form for the user's comment is done in OCL. This approach also provides a significant performance improvement.


The effect of this will be that the UI will update when I like or unlike it, but if someone else does it, it won't update until my session reloads. It will feel like it's responding right away to my like setting, but to other like settings, it will delay because it will only reload when this value is needed the next time. It's slightly off, but I don't think anyone will notice and it's a huge performance boost.
In conclusion, the article highlights different approaches to improve the performance of a comment section in an article. These approaches include selecting the article based on the self and the first comment, using the PSVAL value to calculate the number of comments that are liked, and combining OCLPS and PSEval with OCL. The article provides detailed explanations for each approach and its impact on performance.


=== Watch the Video ===
=== Watch the Video ===

Revision as of 07:43, 2 March 2023

Here's a small model showing how to use the PSEval value - this could also be interesting if you're working with Associations.

OCLps Example Image.png

This model shows a comment section for an article, stored in the database, as one table for the article, one table for the SysUsers, and one table for the comments. We select from the comments an article that points to the self. Because we want to increase the performance, we must decide whether we're going to show a list of articles or one article to load into the memory and sum up.

________________

and select the likes and then show the number. That would require the system to load every comment object into memory and then filter out the ones that have like, that are not null, and see how many they are.

________________

We decide to use the PSEval value and we want an integer. We say self.comments - this is basically the same as it would be in the OCL. We take the comments, select the ones that are liked and take the size of it. In this case, we are also subscribing to the article which means that this would be re-evaluated if the article changes. This will work well to show how many likes exist. If the user likes or unlikes, this value would not change.We will use PSVAL to get all the comments for this article into memory, but only the ones that have like on them. It would still load objects, but not all of them, only the liked ones up to 9,999 in this case, and then we would take the size of that. By loading the objects, we can take this size here after we have loaded the objects.

Another alternative would be to combine OCLPS and PSEval with OCL. We first pick out the comment the user has made. Then we find all the comments and all the objects that have liked on it, except my comment object. and sum these up. We load all the objects except my own objects, and we add my own comment - liked status - manually.

This part will be executed in OCLPS:

(insert image)

and this part will be in OCL:

(image).

The next variant would be to have this as an integer. We calculate the value of every comment except mine. In OCL, which is auto-subscribed, we calculate the liked form for only my comment.

The effect of this will be that the UI will update when I like or unlike the article, but if someone else does it, it won't update until my session reloads. It will delay because it will only reload when this value is needed the next time. It's slightly off, but I don't think anyone will notice and it's a huge performance boost.

Paragraph 2: To show how many likes an article has, three different implementations are presented. One of the implementations is to use the PSVAL value to calculate the number of comments that are liked, without loading all the objects. This is done by selecting the comments, taking the ones that are liked, and determining the size of the selection. By loading only the objects that have been liked, performance is improved.

Paragraph 3: Another implementation is to combine OCLPS and PSEval with OCL. In this approach, the UI updates when the user likes or unlikes, but not when someone else does it. This slight delay is a performance boost and is unlikely to be noticed by users. By using OCLPS, the system loads all the comments except the user's own comments that have been liked and manually adds the user's own comment-liked status. The calculation of the liked form for the user's comment is done in OCL. This approach also provides a significant performance improvement.

In conclusion, the article highlights different approaches to improve the performance of a comment section in an article. These approaches include selecting the article based on the self and the first comment, using the PSVAL value to calculate the number of comments that are liked, and combining OCLPS and PSEval with OCL. The article provides detailed explanations for each approach and its impact on performance.

Watch the Video

This page was edited 67 days ago on 03/12/2024. What links here