Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CommunityPermissions): Fix token criteria updates in the permissions model #14457

Conversation

alexjba
Copy link
Contributor

@alexjba alexjba commented Apr 17, 2024

What does the PR do

Fixes #14446

The tokens criteria items were filtered out if the criteriaMet flag doesn't change after a model update.

This filtering was done due to perf reasons, but we need all the token criteria items in the model.

Affected areas

Community permissions

Screenshot of functionality (including design for comparison)

This shows that both token criteria items are shown in the UI even though one is met and one is not.

Screen.Recording.2024-04-17.at.17.01.59.mov

@status-im-auto
Copy link
Member

status-im-auto commented Apr 17, 2024

Jenkins Builds

Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 57bfb69 #1 2024-04-17 14:25:27 ~7 min tests/nim 📄log
✔️ 57bfb69 #1 2024-04-17 14:26:41 ~8 min macos/aarch64 🍎dmg
✔️ 57bfb69 #1 2024-04-17 14:30:08 ~11 min macos/x86_64 🍎dmg
✔️ 57bfb69 #1 2024-04-17 14:31:03 ~12 min tests/ui 📄log
✔️ 57bfb69 #1 2024-04-17 14:38:47 ~20 min linux/x86_64 📦tgz
✔️ 57bfb69 #1 2024-04-17 14:48:24 ~30 min windows/x86_64 💿exe
✔️ c5a5c8e #2 2024-04-17 18:44:47 ~4 min macos/aarch64 🍎dmg
✔️ c5a5c8e #2 2024-04-17 18:46:38 ~6 min tests/nim 📄log
✔️ c5a5c8e #2 2024-04-17 18:50:55 ~10 min macos/x86_64 🍎dmg
✔️ c5a5c8e #2 2024-04-17 18:51:02 ~10 min tests/ui 📄log
✔️ c5a5c8e #2 2024-04-17 18:55:39 ~15 min linux/x86_64 📦tgz
✔️ c5a5c8e #2 2024-04-17 19:07:10 ~26 min windows/x86_64 💿exe

Copy link
Member

@caybro caybro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find! :)

let criteriaMet = criteriaResult.criteria[index]

if tokenCriteriaItem.criteriaMet == criteriaMet:
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see the mistake I made. If one of the criteria is updated, we update the whole permission, and with my change, we only update/add the criteria that changed.

I think we can still keep the performance improvement by doing it right this time.

We could do something like this:

      var aCriteriaChanged = false
      for index, tokenCriteriaItem in tokenPermissionItem.getTokenCriteria().getItems():
        let criteriaMet = criteriaResult.criteria[index]

        if tokenCriteriaItem.criteriaMet != criteriaMet:
          aCriteriaChanged = true

Then below on line 957, instead of if updatedTokenCriteriaItems.len == 0:, we do if not aCriteriaChanged:.

This should have the right logic where if a criteria was updated, we put all the criterias in the model, but we can keep the performance improvement when none of the criterias changed.

Does it make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then what if something else changes in the tokenCriteria? We'll still show the old data
E.g. TokenCriteria with 1SNT changes to 1ETH, but the user still meets the token criteria

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this model update is really costly we could just compare the old token criteria item with the new one and update only what was changed in the model. I guess this could be done in the model itself because we're duplicating the same logic in 2 places now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then what if something else changes in the tokenCriteria? We'll still show the old data
E.g. TokenCriteria with 1SNT changes to 1ETH, but the user still meets the token criteria

I asked myself this question too last time and it's not handled by this function. Here, we loop permissions, which is a Table containing CheckPermissionsResultDto. And here is the signature for CheckPermissionsResultDto:

type CheckPermissionsResultDto* = object
  criteria*: seq[bool]

As you can see, it only contains the criteria result, so it's ok to only check this property.

Also, updateTokenPermissionModel is only called when we get a response from the check functions (onCommunityCheckChannelPermissionsResponse and onCommunityCheckAllChannelsPermissionsResponse)

if this model update is really costly we could just compare the old token criteria item with the new one and update only what was changed in the model. I guess this could be done in the model itself because we're duplicating the same logic in 2 places now.

@micieslak did that change too. I think it was indeed the most costly part, but it will help too to not call the model functions for no reason.

I guess, you can try your change as is with the Status community (use the edit shared addresses popup) and see if it hangs super long when the result comes back. If it's not too bad, we can use your change.
Do note that you can also remove the rest of the changes I made, because they are no longer in use (thereWasAnUpdate for example)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh, we're receiving here only the bool values for the tokenCriteriaMet. So the community tokensPermissionsModel is updated in other flows. Yeah, will work 👍

I'll test it now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrainville Updated! Thanks 🍻

…ons model

Re-create the token criteria and include all items whenever the model changes.

The previous perf optimisation fix filtered the items where the criteriaMet doesn't change.
@alexjba alexjba force-pushed the 14446-permissions-requirements-that-are-not-met-are-being-hidden-on-the-community-permission-overlay2 branch from 57bfb69 to c5a5c8e Compare April 17, 2024 18:39
Copy link
Member

@jrainville jrainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@alexjba
Copy link
Contributor Author

alexjba commented Apr 17, 2024

@jrainville It's ready for merge

@jrainville jrainville merged commit a9a83df into release/2.28.x Apr 17, 2024
8 checks passed
@jrainville jrainville deleted the 14446-permissions-requirements-that-are-not-met-are-being-hidden-on-the-community-permission-overlay2 branch April 17, 2024 20:11
@caybro
Copy link
Member

caybro commented Apr 18, 2024

@alexjba pls backport to master :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permissions requirements that are not met are being hidden on the community permission overlay
4 participants