Ayende @ Rahien

Refunds available at head office

Streamlined RavenDB, Part I

One of the things that we worked very hard on (and are still working very hard) is making RavenDB as streamlined as possible, in the sense of making it very easy to do things that you commonly have to do.

Case in point, the Future Posts feature of this blog. Yesterday I went a bit overboard and posted about 10 posts in the space of two hours. (No, this isn’t my usual rate). That led to something that I didn’t quite foreseen:

image

We did have a limit on the number of future posts that we will show, but that limit was set to 15, and as you can see, it is actually pretty hard to look at things when we have so many, so instead I decided that we should have the following:

image

Just a minor UI change, but we now need to also change the data that we gather, or do we? Let us look at the code:

image

The only change that I actually had to do was modify the Take() from 15 to 5, and also ask the query to give me the query statistics. Because such as operation (pages + full count) is so common, RavenDB make it super cheap to do so. You don’ t need to issue a separate query, and you don’t need to do anything nor are you incurring any additional costs.

The information is already there.

Tags:

Posted By: Ayende Rahien

Published at

Originally posted at

Comments

Scooletz
07/07/2011 09:10 AM by
Scooletz

Nice. I do like the way of getting things done with Raven. Write a dot and check what features are provided. By the way, are all this extensions (like cache and stats) written in a feature-mode you often describe? Is it a vertical, from the client to the raven server implementation?

Ayende Rahien
07/07/2011 09:19 AM by
Ayende Rahien

Scooletz, Some of them are, bundles, for example. Some are more complex, caching for example, requires us to take explicit action in several places, as did profiling. It really depend on what you are doing, and what extensions points we have there to cover them.

Idsa
07/07/2011 10:22 AM by
Idsa

So I guess usual paging also may be implemented by one query? Nice, never liked the absense of this feature in other database servers.

Ayende Rahien
07/07/2011 10:24 AM by
Ayende Rahien

Idsa, Yep, that is a single call away, and requires no extra work

Daniel Lidström
07/07/2011 10:44 AM by
Daniel Lidström

Where is the 8 coming from? Are you calculating it in the view?

Ayende Rahien
07/07/2011 10:54 AM by
Ayende Rahien

Daniel, It is TotalResults - Posts.Count

Daniel Lidström
07/07/2011 10:57 AM by
Daniel Lidström

Ok thanks, that clarified things a bit for me.

Bogdan Marian
07/07/2011 11:03 AM by
Bogdan Marian

@Ayende Hats on, master! I really, really like the total count + page in the same query... By the way, what are you using behind the call MapTo? AutoMapper or something else?

Bogdan Marian
07/07/2011 11:07 AM by
Bogdan Marian

@Ayende Are you not concerned by the price of using AutoMapper? As far as I know, it's using Reflection for mapping ...

Ayende Rahien
07/07/2011 11:15 AM by
Ayende Rahien

Bogdan, In a word, no. http://ayende.com/blog/4811/performance-numbers-in-the-pub

James Morcom
07/07/2011 11:27 AM by
James Morcom

My main concern with automapper is that renaming a property on my entity could break my views without me realising it - as the corresponding property on the viewmodel won't be renamed.

Marcel Medak
07/07/2011 11:29 AM by
Marcel Medak

Hi Ayende, I see that you explicitly query for posts which are not flagged as deleted. I suppose that most of the time only posts are queried which aren't flagged as deleted and that this must be done explicitly. So my question is if this is something you can avoid?

Ayende Rahien
07/07/2011 11:36 AM by
Ayende Rahien

Marcel, Actually, yes, we could have created an index that would do this filtering for us, certainly.

Gian Maria Ricci
07/07/2011 02:26 PM by
Gian Maria Ricci

Man, this is really really really coool!!!!!

Mario
07/07/2011 03:20 PM by
Mario

Ayende for a long time I would love ask you ...why is Mark Zuckerberg the creator of FB but and not you???

p.s. sometimes (when I have no money) I think mmm ...why i'm not the creator of FB :( ...then I think mmm ...but ayende is not even :)

Tang Biao
07/08/2011 02:53 AM by
Tang Biao

Sorry to ask a junior question, is the source code that contains this sample on github, and which repository? I feel like to take a look.

Bas
07/08/2011 09:10 AM by
Bas

During 1 minute the post is not shown as public post and not as future post. See also: http://ayende.com/blog/26625/you-canrsquo-t-cache-datetime-now

Ayende Rahien
07/08/2011 02:43 PM by
Ayende Rahien

Bas, That is okay, it is perfectly fine or this to happen, since the cost of avoiding it may be too high.

Bas
07/08/2011 02:52 PM by
Bas

What is the cost of changing < into <= in WhereIsPublicPost() or changing > into >= in FuturePosts()

Ayende Rahien
07/08/2011 02:57 PM by
Ayende Rahien

Bas, That isn't the issue, the issue is that they are using slightly different clocks to do that. It may be that they hit just in the 1 minute mark, and get two different minutes

Ayende Rahien
07/08/2011 03:16 PM by
Ayende Rahien

Tang,

http://github.com/ayende/RaccoonBlog

Jeff Handley
07/08/2011 07:27 PM by
Jeff Handley

By having the .Statistics call before the .Where(x => x.IsDeleted == false), does that make the statistics include deleted posts in the counts?

Ayende Rahien
07/08/2011 10:41 PM by
Ayende Rahien

Jeff, No, it doesn't matter where you put the Statistics call

Tang Biao
07/09/2011 04:02 AM by
Tang Biao

Thanks, ayende. Just started to follow your blogs. It has so many things to learn.

Comments have been closed on this topic.