datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
tatut 2021-02-18T08:26:09.297100Z

If I remember correctly, there was some talk about backup/restore functionality for datomic cloud being in the works, but can’t find any news about it. Is that still being worked on?

enn 2021-02-18T19:01:26.298400Z

am I misunderstanding the :limit option to index-pull?

(count
 (d/index-pull db {:index :avet
                   :selector [:db/id]
                   :start [:story/group group-id]
                   :limit 5})))
10
I would expect to get no more than 5 results back. I get back 10 results (the total number of matching results) no matter what limit I specify.

enn 2021-02-18T19:08:10.298900Z

is this feature implemented only for Datomic Cloud? It’s described in the on-prem index-pull documentation.

Joe Lane 2021-02-18T19:09:02.300Z

You can Call (take 5 (d/index-pull ...

enn 2021-02-18T19:10:19.301200Z

Yes, I know, but I was planning to use :limit in conjunction with :offset to do pagination without realizing the full collection of results. (`:offset` does not appear to have any effect either for me.)

Joe Lane 2021-02-18T19:26:13.301600Z

@enn Do you have a link to the docs you're reading?

Joe Lane 2021-02-18T19:27:23.302Z

Thanks

Joe Lane 2021-02-18T19:27:39.302300Z

And you're using on-prem, correct?

enn 2021-02-18T19:27:55.302500Z

Yes

Joe Lane 2021-02-18T19:30:08.302700Z

peer api or client api?

enn 2021-02-18T19:30:47.303Z

This is on a peer

jaret 2021-02-18T20:25:49.304800Z

Hi @ennhttps://docs.datomic.com/on-prem/clojure/index.html#datomic.api/index-pull does not include :limit. This is implemented in the client-api which is accessible in the latest client-pro release https://docs.datomic.com/on-prem/overview/project-setup.html#client-setup

jaret 2021-02-18T20:26:20.305200Z

The reason for this is at the top level of client in https://docs.datomic.com/client-api/datomic.client.api.html#top:

jaret 2021-02-18T20:26:53.306Z

Functions that support offset and limit take the following
additional optional keys:

  :offset    Number of results to omit from the beginning
             of the returned data.
  :limit     Maximum total number of results to return.
             Specify -1 for no limit. Defaults to -1 for q
             and to 1000 for all other APIs.

jaret 2021-02-18T20:27:39.306900Z

I can see how this is confusing in our docs, given the example shows the usage of :limit without the added context above. I will update the docs to reflect that.

jaret 2021-02-18T20:29:09.308200Z

I need to also discuss with the team if peer api will ever support index-pull with limit, but as Joe said, you can still take 5 etc.

1👍
2021-02-22T16:51:13.005100Z

Thanks @jaret this was a confusion point for my team as well

favila 2021-02-18T20:30:48.309400Z

Is the pull realized by advancing the outer seq, or only by reading each entry? E.g. if we go (drop 100 result-of-index-pull), does that do the work of 100 pulls or 0?

favila 2021-02-18T20:35:34.310700Z

(I’m trying to discern if drop is an exact workalike to :offset or potentially much more expensive in the peer api)

jaret 2021-02-18T20:37:04.311300Z

My understanding is it does the work of 100 pulls. But I need to validate that understanding and am running that by Stu.

Joe Lane 2021-02-18T20:45:29.312700Z

@enn Ideally when implementing a pagination api though, you wouldn't use offset like that. Rather, you would grab the last element of the prior page and use that in the value position of :start, or in your case, :group-id.

Joe Lane 2021-02-18T20:46:02.312900Z

@favila ^^

2021-02-18T20:46:52.314400Z

“Cursor based pagination” is the concept Joe Lane is referring to :)!

favila 2021-02-18T20:46:59.314600Z

Sure, ideally. But obviously it’s important enough that the client api has :limit and :offset 🙂

2021-02-18T20:48:04.314800Z

pretty mind blown when I first saw it in GraphQL land, pretty cool actually!

favila 2021-02-18T21:02:10.315Z

What you’re suggesting would be more complex than this in the general case. You would have to retain the last pull of the page, transform it back into the next :start vector (which may have grown longer if e.g. a group spans multiple pages), serialize that as a cursor for the client, then rehydrate it when it comes back and know to skip the first result if it is an exact match for :start. I can definitely see not wanting to take all that on in an initial implementation. It also makes it difficult to have a non-opaque cursor--a client may indeed want to skip 100 items or pipeline multiple fetches and be ok with the potentially inconsistent read.

favila 2021-02-18T21:02:21.315200Z

IOW simple offset and limit still has its uses

enn 2021-02-18T21:15:25.316400Z

@jaret thanks for the clarification, I appreciate it. If you hear anything back on whether this will be supported in the future I’d love to hear.