Skip to content

Commit

Permalink
keeps inserted_at value on update, #30
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLab committed Feb 5, 2019
1 parent 530f7e0 commit 7d46a3a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
22 changes: 0 additions & 22 deletions lib/alog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ defmodule Alog do
|> Map.get(:data)
|> @repo.preload(__MODULE__.__schema__(:associations))
|> Map.put(:id, nil)
|> Map.put(:inserted_at, nil)
|> Map.put(:updated_at, nil)

changeset
Expand Down Expand Up @@ -248,19 +247,6 @@ defmodule Alog do
User.all()
"""
def all do
# get the oldest items
sub =
from(m in __MODULE__,
distinct: m.entry_id,
order_by: [asc: :inserted_at],
select: m
)

query = from(m in subquery(sub), where: not m.deleted, select: m)

oldest_items = @repo.all(query)

# get the most recent inserted items, ie desc: :inserted_at
sub =
from(m in __MODULE__,
distinct: m.entry_id,
Expand All @@ -271,14 +257,6 @@ defmodule Alog do
query = from(m in subquery(sub), where: not m.deleted, select: m)

@repo.all(query)
|> Enum.map(fn(newest_item) ->
oldest_item = Enum.find(oldest_items, &(&1.entry_id == newest_item.entry_id))
if oldest_item do
%{newest_item | inserted_at: oldest_item.inserted_at}
else
newest_item
end
end)
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Alog.MixProject do
def project do
[
app: :alog,
version: "0.4.2",
version: "0.4.3",
elixir: "~> 1.7",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit 7d46a3a

Please sign in to comment.