Limit Fever unread items API to 10k most recent

This commit is contained in:
Shadowfacts 2020-10-24 14:05:04 -04:00
parent 8e18a415eb
commit 375406a8df
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 19 additions and 13 deletions

View File

@ -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") ->
item_ids =
params["with_ids"]
|> String.split(",")
|> Enum.map(fn id ->
{id, _} = id |> String.trim() |> Integer.parse()
item = Repo.get(Item, id)
if not is_nil(item) and item.feed_id in feed_ids do
item
else
nil
end
|> Enum.map(fn str ->
{id, _} = str |> String.trim() |> Integer.parse()
id
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"])