Last active
March 15, 2019 10:54
-
-
Save hubertlepicki/e78b518ad7be20142ddb173f1d717ce5 to your computer and use it in GitHub Desktop.
benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = "query { | |
project(id: 1389) { | |
id, | |
slices { | |
id, | |
todos { | |
id, | |
title, | |
description, | |
progress, | |
position, | |
status, | |
dependencies_type, | |
start_date, | |
due_date, | |
snooze_date, | |
duration, | |
slice_id, | |
box_id, | |
todo_id, | |
workspace_id, | |
deleted_at, | |
checklist { | |
title, | |
done | |
}, | |
predecessors { | |
id, | |
title, | |
slice_id, | |
slice { | |
id, | |
title, | |
project_id, | |
project { | |
id, | |
title | |
} | |
}, | |
box { | |
id, | |
title | |
} | |
}, | |
files { | |
id, | |
url, | |
url_name, | |
mime_type, | |
user_id, | |
user_name, | |
project_id, | |
slice_id, | |
todo_id, | |
recipe_id, | |
recipe_slice_id, | |
recipe_todo_id, | |
folder_id, | |
deleted_at, | |
updated_at | |
}, | |
assignments { | |
id, | |
user_id, | |
user { | |
id, | |
email, | |
first_name, | |
last_name, | |
avatar_url | |
} | |
} | |
} | |
} | |
} | |
}" | |
user = Core.Users.Finder.get(136) | |
Benchee.run(%{ | |
"absinthe query" => fn -> Absinthe.run(query, Core.Schema, context: %{current_user: user}) end, | |
"ecto query" => fn -> project = Core.FindProject.find_project(1389, user); Core.ListSlices.list_slices(project, true) end}, time: 10, memory_time: 2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_slices(project, true) do | |
from(slices in DB.Slice, | |
where: slices.project_id == ^project.id, | |
order_by: [asc: slices.position], | |
left_join: todos in DB.Todo, | |
on: todos.slice_id == slices.id and is_nil(todos.deleted_at), | |
order_by: [asc: todos.position], | |
left_join: todo_predecessors in DB.Predecessor, | |
on: todo_predecessors.predecessor_of_todo_id == todos.id, | |
left_join: predecessors in DB.Todo, | |
on: predecessors.id == todo_predecessors.todo_id and is_nil(predecessors.deleted_at), | |
order_by: [asc: predecessors.position], | |
left_join: predecessor_slice in assoc(predecessors, :slice), | |
left_join: predecessor_project in assoc(predecessor_slice, :project), | |
left_join: box in assoc(predecessors, :box), | |
left_join: files in DB.File, | |
on: files.todo_id == todos.id and is_nil(files.deleted_at), | |
left_join: assignments in assoc(todos, :assignments), | |
left_join: assigned_user in assoc(assignments, :user), | |
preload: [ | |
todos: | |
{todos, | |
files: files, | |
assignments: {assignments, user: assigned_user}, | |
todo_predecessors: todo_predecessors, | |
predecessors: | |
{predecessors, box: box, slice: {predecessor_slice, project: predecessor_project}}} | |
] | |
) | |
|> DB.Repo.all() | |
end | |
def find_project(id, %{} = user, action) do | |
project = | |
from( | |
p in DB.Project, | |
where: p.id == ^id, | |
where: is_nil(p.deleted_at) | |
) | |
|> DB.Repo.one() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment