Concept: mark task as seen, mark task as completed

I have users that are grouped together in a team to work on a project together.

I am creating a schema to track when each team member on the projects has:

  • seen a task
  • completed the task.

This is the schema that I have come up with so far:

Dgraph Schema
Name: string .
IsOwnedBy: uid .
TeamMembers: [uid] .
HasTasks: [uid] .
Seen: bool .
Completed: bool .

type User {
    Name
}
type Project {
    Name
    IsOwnedBy
    TeamMembers
    HasTasks
}
type Task {
    Name
}
type TeamMember {
    Name
    HasTasks
}

I can add some data to the graph:

Data Mutation
{
    set {
        _:jack <Name> "Jack" .
        _:jack <dgraph.type> "User" .
        _:jill <Name> "Jill" .
        _:jill <dgraph.type> "User" .

        _:project1 <Name> "Do All The Tasks" .
        _:project1 <dgraph.type> "Project" .
        _:project1 <IsOwnedBy> _:jack .

        _:jack <TeamMember> _:project1 .
        _:jill <TeamMember> _:project1 .

        _:task1 <Task> "The First Task" .
        _:task2 <Task> "The Second Task" .

        _:project1 <HasTasks> _:task1 .
        _:project1 <HasTasks> _:task2 .

        _:jack <HasTasks> _:task1 (seen=false, completed=false) .
        _:jack <HasTasks> _:task2 (seen=false, completed=false) .

        _:jill <HasTasks> _:task1 (seen=false, completed=false) .
        _:jill <HasTasks> _:task2 (seen=false, completed=false) .
    }
}

But the result is not really what I was expecting.
Screenshot 2024-03-15 at 08.43.13

A Project should have a list of “Tasks”. And then the Users who are also TeamMembers should have a copy of all of the tasks when they are added to the project so that they can mark whether they have “seen” and then “completed” those tasks. Each TeamMember must complete each task.

I think my brain is still stuck in the RDBMS world.

  • Do I even need a “TeamMember” type?
  • Or would the TeamMember just be a list of Users?
  • How would each TeamMember get a copy of the Tasks?
  • Or perhaps each TeamMember just has an edge to each task and facets that indicate “seen” and “completed”… :thinking:

When a User is added to a Project, would it be better to create edges that connect each User to each Task? Or only create an edge/connection to each task once the user sees it?

Would it make more sense to have “Seen” and “Completed” be individual edges or facets on a single edge?

And then when I need to query all the tasks for a user on a specific project, I could get a list of all Tasks connected to the User, but how do I know which Tasks that are connected to the User are also part of the specific Project, since a User could be connected to multiple Projects…

I think TeamMember is not helping you, because being on a Team is not a long-term managed “thing” but is implicit in the User being linked to a Project. The relation in Dgraph is the edge (which can then have some facets as properties as you know). There is often no need for an entity that is like a RDBMS join table.

If there are Teams that exist such as “The DevOps Team” or “The QA Team” that would be different, but yours seem to be implicit in the Project staffing.

By convention, I suggest entities/types be capitalized (Project, User) and relations and fields lowercase (onProject, projectOwner, hasTask).

It will be simpler and often faster to directly link a User to a Project and add the facet for “hasSeen.” However, facets are always internally processed by an internal filtering process in Dgraph, vs indexing and link navigation. So if you need to do big queries such as counting all the Tasks “seen” in the last week across 100 projects, you may want an Activity or SeenEvent to be in the DB as it’s own Entity with its own fields to facilitate efficient query.

I suspect isCompleted is different because that is fundamental to the Task - is it done or not - and not really about the User activity. You will likely want to report on and filter to completed vs active tasks often.

So I would usually put isCompleted on the Task, and perhaps add a “completedBy” relation to the user(s) who completed it.

But your specifics may be different, so these are general guidelines. Good luck!

1 Like