Question

When my C#, WPF UI starts, one of the tabs calls this code when loading. The most recent data displayed is 11-Feb-2012, even though there are InstallationSummary documents for 15-Feb-2012. When I hit the refresh button, this exact same code is called, only this time the most recent results are displayed. How can the same code produce two different results?

IQueryable<EntityBase> installationSummaries =
  QueryAndSetEtags(session => session.Query<InstallationSummary>()
  .Include(x => x.ApplicationServerId)
  .Include(x => x.ApplicationWithOverrideVariableGroup.ApplicationId)
  .Include(x => x.ApplicationWithOverrideVariableGroup.CustomVariableGroupId)
  .OrderByDescending(summary => summary.InstallationStart)
  .Take(numberToRetrieve));

Note: I'm having the exact same issue with another query. It seems as if I haven't queried in a while, I get the incorrect results. If I query again right after I just did it, I get the right results. I'm wondering if I have to create an index. There are over 10,000 InstallationSummary documents, and the performance is just fine. It's the accuracy that I'm having trouble with.

Was it helpful?

Solution

Sounds like a stale index issue. Try to add this line and see if that helps

.Customize(x => x.WaitForNonStaleResultsAsOnNow())

Update: It is better to use WaitForNonStaleResultsAsOnNow() than WaitForNonStaleResults()

Edit: Why is that?
The reason is, that your query will create a temporary index that automatically will be deleted after some time of inactivity. Further, they will not survive a restart of RavenDB. Now you have a few option:

  • promote the index to be permanent using the management studio

  • create an index within your application and use that index when querying

  • wait for raven to self optimize itself and promote the index automatically (this will only happen if the query will be run often enough, which seems unlikely in your case)

  • use the .WaitForNonStaleResuls() option as outlined above (this is worst because it can have a very negative impact on application performance and there's no need to because the other options are much better)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top