Limit Fever unread items API to 10k most recent
This commit is contained in:
parent
8e18a415eb
commit
375406a8df
|
@ -196,7 +196,12 @@ defmodule FrenzyWeb.FeverController do
|
|||
|> Enum.map(fn f -> f.id end)
|
||||
|
||||
unread =
|
||||
Repo.all(from i in Item, where: i.feed_id in ^feed_ids, where: [read: false])
|
||||
Repo.all(
|
||||
from i in Item,
|
||||
where: i.feed_id in ^feed_ids and not i.read,
|
||||
limit: 10000,
|
||||
order_by: [desc: :id]
|
||||
)
|
||||
|> Enum.map(fn item -> item.id end)
|
||||
|> Enum.join(",")
|
||||
|
||||
|
@ -222,19 +227,20 @@ defmodule FrenzyWeb.FeverController do
|
|||
items =
|
||||
cond do
|
||||
Map.has_key?(params, "with_ids") ->
|
||||
params["with_ids"]
|
||||
|> String.split(",")
|
||||
|> Enum.map(fn id ->
|
||||
{id, _} = id |> String.trim() |> Integer.parse()
|
||||
item = Repo.get(Item, id)
|
||||
item_ids =
|
||||
params["with_ids"]
|
||||
|> String.split(",")
|
||||
|> Enum.map(fn str ->
|
||||
{id, _} = str |> String.trim() |> Integer.parse()
|
||||
id
|
||||
end)
|
||||
|
||||
if not is_nil(item) and item.feed_id in feed_ids do
|
||||
item
|
||||
else
|
||||
nil
|
||||
end
|
||||
end)
|
||||
|> Enum.reject(&is_nil/1)
|
||||
Repo.all(
|
||||
from i in Item,
|
||||
where: i.id in ^item_ids,
|
||||
where: i.feed_id in ^feed_ids,
|
||||
where: not i.tombstone
|
||||
)
|
||||
|
||||
Map.has_key?(params, "since_id") ->
|
||||
since = Repo.get(Item, params["since_id"])
|
||||
|
|
Loading…
Reference in New Issue