Twitter-like model with RavenDB

I will play a little with Raven and try to figure out what the best way would be to model my objects for a scenario like a tweeter. So far I have come up with several options, but I'm not sure which one is the best.

public class User{
    public string Id{get;set;}
    public List<string> Following{get;set;}
    public List<string> Followers{get;set;}
}

The custom object is simple and simple, just an identifier and a list of identifiers for the people I follow and the people following me. Setting up a feed is where I need help getting all the messages from users that I follow.

Option 1 - Easy Route

This is a search for all messages of people whom I adhere only based on their UserId.

public class Post{
    public string UserId{get;set;}
    public string Content{get;set;}
}

Index

public class Posts : AbstractIndexCreationTask<Post>{
    public Posts(){
        Map = results => from r in results
                         select new{
                             r.UserId
                         };
    }
}

Inquiries

var posts = session.Query<Post,Posts>().Where(c=>c.UserId.In(peopleImFollowing));

, . OR, Lucene. - 1024, Raven, 1000 .

2 -

public class Post{
    public string UserId{get;set;}
    public string RecipientId{get;set;}
    public string Content{get;set;}
}

foreach(string followerId in me.Followers){
   session.Store(new Post{
    UserId = me.UserId,
    RecipientId = followerId,
    Content = "foobar" });
}

, , , ... , , ?

3 -

.

public class Post{
    public string UserId{get;set;}
    public List<string> Recipients{get;set;}
    public string Content{get;set;}
}

public class Posts : AbstractIndexCreationTask<Post>{
    public Posts(){
        Map = results => from r in results
                         select new{
                             UserId = r.UserId,
                             Recipient = r.Recipients
                         }
    }
}

session.Store(new Post{
               UserId = me.Id,
               Recipients = me.Followers,
               Content = "foobar"
              });

var posts = session.Query<Post,Posts>().Where(c=>c.Recipient == me.Id);

, . , - 10 000 ? , , ? , ?

+3
1

, 1, , , , RavenDB lucene, 1024 .

2 3 , , , , . , , , . , "follow", "unfollow". / , (, , , , ?).

2 , , . . ... .

3 , , lucene "", , . ... , lucene, , , ( , , ).

As I said above, I think that only option 1 works. Perhaps someone has a better approach. Good question by the way.

+1
source

All Articles