concept user in category ravendb

appears as: users, user, The user, user
RavenDB in Action

This is an excerpt from Manning's book RavenDB in Action.

Data persistence is at the heart of every technology project. Whether it’s to remember users and their preferences, gather statistics and numbers for later crunching, sell products out of a catalog, save logs, or count Facebook “likes,” data has to be stored. Although data can be safely stored even on tapes, most of the time we need it accessible for quick retrieval to display it or for further processing, and to do that we need the ability to query.

using System.Linq; using System.Web.Mvc; using Chapter02Bookstore.Models; using Raven.Client; namespace Chapter02Bookstore.Controllers { public class BooksController : RavenController #0 { public ActionResult ListAll() { var books = RavenSession.Query<Book>().ToList(); #A #B #C return View("List", books); #D } } } #0 – By inheriting from RavenController we gain access to the RavenSession object, which is now initialized and ready for us to work with #A – Starts to construct a query #B – Asks for documents of the Books collection #C – Executes the query #D – Passes the resulting List<Book> to the View for rendering the page to the user

One option is to go through all the documents in the system and check them to see if they match the query. This will work, sure, if the user who issued the query is kind enough to wait for a few hours in a large system. But no user is. In order to efficiently satisfy user queries you need to have your data indexed. By using indexes the software can perform searches much more efficiently and complete queries much faster.

Before we look at those indexes, let’s consider for a moment when are they going to be built or updated with the new documents that come in. If you calculate them when the user issues the query, you delay returning the results. This is going to be much less substantial than going over all the documents, but you still incur a performance hit to the user for every query they make.

Another perhaps more sensible option is to update the indexes when the user puts in the new documents. This makes more sense at first, but then when you start to consider what it would take to update several complex indexes on every put, it becomes much less attractive. In real systems, this means writes would take quite a lot of time, because now not only is the document being written, but all indexes have to be updated as well. There’s also the question of transactions—what happens when a failure occurs while the indexes are being updated; should it fail a transaction? And how do you handle concurrent writes?