maz

maz

Paginator Cursor Missing Items

I have a query containing a relatively complicated join and there are 85 items total.

Strangely, after sending the second after cursor no more items return(Paginator never returns more than 60 items).

This is the query:

  defp list_media_items_by_channel_slug_query(channel_slug, :feed) do
    from(m in MediaItem,
      join: con in ContentMediaItems,
      on: m.id == con.media_item_id,
      join: chan in assoc(con, :channel),
      where: chan.slug == ^channel_slug,
      preload: [:mediaitemartifacts],
      order_by: [{:desc, :inserted_at}]
    )
  end

Called like:

        %{entries: entries, metadata: metadata} =
          Repo.paginate(
            query,
            include_total_count: true,
            after: after_cursor,
            sort_direction: sort_direction,
            cursor_fields: cursor_fields,
            limit: 30
          )

The first cursor returns another 30, but the second cursor returns nothing, but when I get the full list there are 85 items(so the cursor should return 25, but actually returns 0).

Repo.all(query) # returns 85

I’m baffled. The 25 items are there but I don’t get them returned?

Elixir 1.16.1 (compiled with Erlang/OTP 26)
ecto 3.11.2
paginator, 1.1.0

Marked As Solved

maz

maz

I found a fix, and you led me down the trail, thanks.

cursor_fields: [:inserted_at, :title],

If I use these two columns, it gives the paginator enough to work with and I receive the correct result sets. I think a lot of the inserted_at dates are too similar.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement