I thought of this:
Three nodes: User, post, and like
type User{
posts: [Post]
likes: [Like]
}
type post{
likes: [Like]
author: User
}
type Like{
time
Likeby User
LikedOn Post
}
Now if a user likes a post. A new node will be added with edge to post and user.
But with this method, I can not find if a user has liked the post or not.
I can also directly set edge between user and post to track likes. But what if user unlikes and likes it again. I want to know if this happens.
This is business logic and there are several different ways to handle it. Each different way to implement this has its own tradeoffs. do you want to store a list somewhere of sent notifications, or do you want to perpetually store a Like with a delete boolean field that you change if a user deletes the like, but you keep the node itself. But then you have to factor that in when counting likes for posts⌠This is what makes every schema structure unique and why not every schema is the same because of business logic like this and how the developer wants to handle unique edge cases.
Anything with cascade has the possibility to query more data from the disk and then remove extra nodes before final return.
With cascade, it retrieves all Likes from disk and all of the queried edges and predicates before trimming it down to just what you want. But to be clear, it does not get all of the edge node values because there is a filter on the likedBy edge which makes that edge only get the ones matching that filter.
You are thinking of indexing in terms of relational databases and not a graph database. Edges do not have indexes how you are thinking of indexing. If you want a deeper understaning you should go download the Dgraph whitepaper
Yeah, the schema is designed like a relational DB. With 2 âtablesâ, and a 3rd âtableâ which is just connecting the two tables. Instead, it should be like this:
type Post {
Author: User
LikedBy: [User] @reverse # Add reverse index, so you can query User -> all the posts they liked.
Text: String
CreatedOn: Datetime
EditedOn: Datetime
VisibleTo: ... # if you care about privacy.
}
type User {
Name: String
...
}
type Post {
Author: User
LikedBy: [User] @reverse # Add reverse index, so you can query User -> all the posts they liked.
Text: String
CreatedOn: Datetime
EditedOn: Datetime
VisibleTo: ... # if you care about privacy.
}
Can I find if the edge âLikedByâ exists between Post and User efficiently?
Will this query be fine in terms of lookup?
I think that all user nodes will not be read from the disk in this query? Right?