How to efficiently CheckPermissions on a large list of TreeNodes in MVC.

Jordan Whiteley asked on April 19, 2019 06:45

The situation is that I have an expensive query that I'm running that pulls in a moderate amount of tree nodes (200-400) and does some time intensive work getting them ready for display. I don't want to do this work on every call so I'm caching the result for a few hours.

What I'm running into is that when users request this page I want to pull the expensive object out of the cache and be able to 'tag' the items that they don't have access to (Upgrade your membership to get access to...). Currently the only way I've found to do this is to run .CheckPermissions() on each of the 200-400 tree nodes individually.

Is there any faster solution to this situation?

I've tried rerunning the multi-document query with .CheckPermissions() doesn't work because that just doesn't return nodes I can't see. I want to see them and tag them appropriately.
Also running the query twice once with CheckPermissions and once without and diffing the list to tag it properly also seems awful.

Hopefully someone else has run into this and is willing to help. Thanks!

Correct Answer

Roman Hutnyk answered on April 19, 2019 09:29

If access to pages is configured based on roles, you could try to select ACL setting for each page along with page data - this will definitely make the query more heavy, but caching somewhat handles this.

So once you have all pages with roles, those can access it you'll need to get all roles of current user and loop through documents to see if any of user role is present in page ACL settings.

Let's consider you have 400 pages with 10 roles each and user has 5 roles in average, so we got 400 * 10 * 5 = 20'000 checks on backend. Not sure this is acceptable load in your case, but it is definitely much lighter than .CheckPermissions(), as it does not query database cor each check.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Jordan Whiteley answered on April 19, 2019 15:15

@Roman Hutnyk: I'd like to benchmark it but when you say "select ACL setting for each page along with page data" how would you go about this?

I'm currently using document query on an K11 mvc site and I'm not seeing any options. Should I switch to straight sql?

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on April 19, 2019 16:27

Jordan, you're right - it is not possible to achieve it with document query unfortunately.

So yeah, if you consider this to be an option you should either switch to sql, or, maybe, keep document query for page data, but run another custom sql query to get pages' ACL.

0 votesVote for this answer Mark as a Correct answer

Jordan Whiteley answered on April 19, 2019 16:43

Thanks @Roman Hutnyk!

I got to work this morning and asked Brian McKeiver and he gave me a very similar answer. So looks like it's not an easy solution, but it's the right direction to go.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.