RavenDB: Raven Query does not return the correct account with document authorization

public class EngineInfo { public int Id{get;set;} public int? AircraftId { get; set; } public string SerialNumber { get; set; } public int Position { get; set; } public string RegNumber { get; set; } } 

// Here is the code that uses the above model. I have 17,000 documents with this model.

  ravenSession.Store(new AuthorizationUser { Id = "Authorization/Users/1", Name = "user-1", Permissions = { new OperationPermission { Allow = true, Operation = "EngineInfos/View", Tags = "Company/100" } } }); 1. var query = ravenSession.Query<EngineInfo>(); 

// When I write query.Count (), I see all the documents count ie., 17000. This ignores the authorization set in the before statement. If I add a where clause to the above statement, it works, and I could see the correct score. But I want to get all the documents for which the user has authorization.

  2. var query = ravenSession.Query<EngineInfo>().ToList(); 

Now I get the correct account, taking into account authorization. But the problem is that if I don't mention Take (x), it will not return all the results. I tried using

  RavenQueryStatistics queryStats; query.Statistics(out queryStats); queryStats.TotalResults 

I still have not been able to get authorized results. I get all the bills.

Could you help me figure out the TotalCount search for query results without loading all the records?

My requirement is to display all the engines in the ExtJS substring search grid. I need to know the total number of records to display the calculation and display the number of pages (the number of pages is fixed).

+3
source share
2 answers

This is by design, see http://ravendb.net/docs/intro/safe-by-default .

session.Query<Post>().Count() will give you the number of all messages on the server, and session.Query<Post>().ToList().Count() will give you the number of messages that have been selected by the client.

By default, RavenDB applies .Take (128) to the request to encourage you to pager and be safe by default. If you want to get more, then you need to specify how much you need to take, for example .Take(1024) , but by default the server will not return more than 1024 elements at a time. You can configure the server for this, but this is not recommended. You use paging much better, because the user cannot handle so much information anyway.

+1
source

What you see is that Raven QueryStatistics ignores the authorization package. This one was listed in the Google Raven group .

As far as I can tell, at the time of writing this document there is no reliable way to get the total number of allowed documents for the request. It seems to me that the authorization package should contain some support for this.

I will review it and update this answer when I find out more.

0
source

Source: https://habr.com/ru/post/1500349/


All Articles