Coder Social home page Coder Social logo

Comments (9)

tarsius avatar tarsius commented on June 16, 2024 1

I have just pushed better unpaginating support and later today I will probably push support for asynchronous requests, which will improve unpaginating further.

(length (ghub-get "/users/tarsius/repos"))

(length (ghub-get "/users/tarsius/repos" '((per_page . 100))))

(length (ghub-get "/users/tarsius/repos" nil :unpaginate t))

(length (ghub-get "/users/tarsius/repos" '((per_page . 4)) :unpaginate t))

(length (ghub-get "/users/tarsius/repos" '((per_page . 4)) :unpaginate 3))

Asynchronous requests will allow controlled unpaginating without the need for global state.

(ghub-get "/users/tarsius/repos" nil
          :unpaginate t
          :callback (lambda (value _headers _status _args)
                      (setq my-value value)))

(ghub-get "/users/tarsius/repos" nil
          :callback (lambda (value _headers _status args)
		      (unless (ghub-continue args)
			(setq my-value value))))

These two forms are basically equivalent, but the second could be extended to only unpaginate if some condition is met (most likely if not too much time has passed already).

from ghub.

vermiculus avatar vermiculus commented on June 16, 2024

I can try to work on a solution some time next week, but honestly I can't think of anything satisfactory without introducing either

  • a dynamic variable set in ghub-request that indicates if a link exists (regardless of unpaginate)
  • some abstracted response to store the link to the next page of responses along with functions ghub-next-page (or somesuch) to interact with that abstraction. This would be a breaking change, but it's probably more powerful while maintaining some simplicity.

What are your thoughts?

from ghub.

tarsius avatar tarsius commented on June 16, 2024

Sounds like you want to handle this outside of ghub.

How about allowing ghub-request's UNPAGINATE argument to be an integer or even (NUMBER-OF-REQUESTS . ITEMS-PER-REQUEST) instead?

from ghub.

vermiculus avatar vermiculus commented on June 16, 2024

I'm not against ghub handling it, but it does strike me as counter to ghub's minimalist goals. Then again, how do you plan to handle this problem in magit? It's worth some thought.

That consideration notwithstanding, there's only one thing needed for controlled pagination -- three for complete control: where to start returning results. IIRC, this is usually controlled by the page query parameter. The other two are:

  • how many objects per page (default determined by API; I think it's 30)
  • how many pages to retrieve (default 1)

For the first piece -- the page piece -- ghub clients can't give meaningful input unless they know where the previous results dropped off. There has to be some returned value -- whether that's dynamic state (which is gross, I agree) or by a formally returned value (which will be a breaking change). While they may exist, I'm not aware of other options ☚ī¸

from ghub.

vermiculus avatar vermiculus commented on June 16, 2024

I missed an option -- it is possible (though a duplication of work across clients) to keep track of which page of each resource was last retrieved. That should be possible to do at the ghub+ level, at which point I'd probably opt for cl-structs (blech!).

Unless there's a better way to do it, of course.

Magit will eventually have this problem, too, since many repositories maintain >30 open PRs:

from ghub.

tarsius avatar tarsius commented on June 16, 2024

Does the graphql api also return paginated results?

from ghub.

vermiculus avatar vermiculus commented on June 16, 2024

It does, but it's a little different. GraphQL has a concept of a cursor that it prefers over other methods.

Wondering what you're thinking, here -- as far as ghub is concerned, v4 GraphQL is accessed the same way as v3 REST (I'm pretty sure); see examples.el@b0bd6c.

from ghub.

vermiculus avatar vermiculus commented on June 16, 2024

While setting a dynamic variable would be an easy fix, I don't think it's the right thing to do -- especially with the impending advent of multithreaded elisp.

from ghub.

vermiculus avatar vermiculus commented on June 16, 2024

thanks!!

from ghub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.