Hi PowerApps colleagues!
I'm having troubles with the following case:
- I have an app that contains knowledge articles.
- The app is based on Azure SQL DB as data source. The data source contains 2 tables: Articles & Article_Likes (sub-table containing all the people who liked the articles.)
- A user can check the details of an article. On the detailed screen there is a count of all the amount of likes for this article, the like/unlike functionality and a button to navigate to a screen where you can see all users who have like the article.
- The like/unlike functionality checks if you as a user already liked the article. If yes, the description is 'unlike', if no, then 'like'
- The query behind this button is shared below and this causes the biggest issue: performance.
- The performance issues are on multiple levels: when you load the article screen, it takes too long to load the value of the count field, and the logic to check if you already liked the article or not. As a result a user might think he/she didn't like it yet and press the button.
- Another issue is when you actually press the like/unline button. The series of checks & patches/deletes that occur causes confusion at the end user who thinks that it didn't work and presses again and again...
So basically my question (and hopefully I'm doing it terribly wrong here): what is wrong in the below 'onselect' statement which causes this performance issues?
Thanks!
If(
First(varLikeButton).Value = true,
Remove(
'[dbo].[article_Likes]’,
First(
Filter(
'[dbo].[article_Likes]’,
ArticleNumberID = ElementRecord2.ID && Person = Label3.Text
)
)
),
Patch(
'[dbo].[article_Likes]’,
Defaults(
'[dbo].[article_Likes]’
),
{
ArticleDate: ElementRecord2.Created_x0020_Date,
ArticleNumberID: ElementRecord2.ID,
Person: User().Email
}
)
);
If(
First(varLikeButton).Value = true,
Patch(
'[dbo].[Sheet1$]’,
LookUp(
'[dbo].[Sheet1$]’,
ID = ElementRecord2.ID),
{
eLikeCount: If(
First(varOldCount).Value - 1 < 0,
0,
First(varOldCount).Value - 1)
}
),
Patch(
'[dbo].[Sheet1$]’,
LookUp(
'[dbo].[Sheet1$]’,
ID = ElementRecord2.ID
),
{
eLikeCount: First(varOldCount).Value + 1
}
)
);
If(
First(varLikeButton).Value = true,
ClearCollect(
varOldCount,
First(varOldCount).Value - 1
),
ClearCollect(
varOldCount,
First(varOldCount).Value + 1
)
);
Refresh('[dbo].[Sheet1$]’);
Refresh('[dbo].[article_Likes]’);
ClearCollect(varLikeButton, !First(varLikeButton).Value)