forked from thechangelog/changelog.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.iex.exs
45 lines (40 loc) · 788 Bytes
/
.iex.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
alias Changelog.{
Buffer,
Repo,
Person,
Episode,
EpisodeHost,
EpisodeGuest,
EpisodeRequest,
Github,
NewsAd,
NewsItem,
NewsItemComment,
NewsSource,
NewsSponsorship,
NewsQueue,
Podcast,
Post,
Sponsor,
Subscription,
Topic
}
import Ecto
import Ecto.Changeset
import Ecto.Query, only: [from: 1, from: 2]
defmodule Benchmark do
def measure(function) do
function
|> :timer.tc()
|> elem(0)
|> Kernel./(1_000_000)
end
end
defmodule H do
def get(Episode, id), do: Repo.get(Episode, id) |> Repo.preload(:podcast)
def get(model, id), do: Repo.get(model, id)
def update(model, id, attrs \\ %{}) do
Repo.update(Ecto.Changeset.change(Repo.get(model, id), attrs))
end
def delete(model, id), do: Repo.delete(get(model, id))
end