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:
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:
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:
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.
Comments
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?
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.
So I guess usual paging also may be implemented by one query? Nice, never liked the absense of this feature in other database servers.
Idsa, Yep, that is a single call away, and requires no extra work
Where is the 8 coming from? Are you calculating it in the view?
Daniel, It is TotalResults - Posts.Count
Ok thanks, that clarified things a bit for me.
@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<FuturePostViewModel>? AutoMapper or something else?
Bogdan, Yes, automapper
@Ayende Are you not concerned by the price of using AutoMapper? As far as I know, it's using Reflection for mapping ...
Bogdan, In a word, no. http://ayende.com/blog/4811/performance-numbers-in-the-pub
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.
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?
Marcel, Actually, yes, we could have created an index that would do this filtering for us, certainly.
@James Isn't that what Mapper.AssertConfigurationIsValid() is for?
Man, this is really really really coool!!!!!
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 :)
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.
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
Bas, That is okay, it is perfectly fine or this to happen, since the cost of avoiding it may be too high.
What is the cost of changing < into <= in WhereIsPublicPost() or changing > into >= in FuturePosts()
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
Tang,
http://github.com/ayende/RaccoonBlog
By having the .Statistics call before the .Where(x => x.IsDeleted == false), does that make the statistics include deleted posts in the counts?
Jeff, No, it doesn't matter where you put the Statistics call
Thanks, ayende. Just started to follow your blogs. It has so many things to learn.
Comment preview