Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch support #13

Open
asolove opened this issue Jul 28, 2015 · 10 comments
Open

Batch support #13

asolove opened this issue Jul 28, 2015 · 10 comments

Comments

@asolove
Copy link
Contributor

asolove commented Jul 28, 2015

I would like to add support for batch requests. I think this will necessitate some design changes. In particular, I think it means many of the API methods should return a request instead of a response, and then adding a new function that sends one or a batch of requests together and returns a response.

Here's how it might(?) look:

pages = Repo.all(Page)
  |> Enum.map(fn page -> Facebook.page(page.facebook_page_id) end)
  |> Facebook.requestBatch()
@mweibel
Copy link
Owner

mweibel commented Jul 28, 2015

looks ok to me, however I'm thinking how we could support both, so that we don't always need to request a batch if not needed.. Do you have an idea?

@asolove
Copy link
Contributor Author

asolove commented Jul 28, 2015

I would prefer to not have two separate versions of each function. One cool feature of other libraries I've worked with is that you can open a batch, call functions that make requests, and have them automatically batched up without knowing they're participating in the batch. Not sure how to make that happen in Elixir.

@mweibel
Copy link
Owner

mweibel commented Jul 29, 2015

Could you show me such a library so I'd get a clearer view how they're doing that?

@asolove
Copy link
Contributor Author

asolove commented Jul 30, 2015

The specific example I know best is koala in ruby. Here's a simple snippet:

@graph.batch do |batch_api|
  # Assuming you have database fields "about_me" and "photos"
  batch_api.get_object('me')                {|me|     self.about_me = me }
  batch_api.get_connections('me', 'photos') {|photos| self.photos   = photos }
end

In this case the two calls to the batch api get put together, the responses to the batch are taken apart and the correct one is fed to each block and the block called before the batch call finishes.

In Elixir's semantics, we'd probably want to do that differently, and I don't know how. But doing large-scale work with Facebook without batching is going to be painful.

@mweibel
Copy link
Owner

mweibel commented Aug 4, 2015

Hey,
sorry for not coming back to you earlier. Sounds like a cool API but I'm unsure as well how to do that (without some macro stuff which makes it a bit harder to follow the code).
So I propose for now to go for the first proposal you had. Do you agree?

@mweibel
Copy link
Owner

mweibel commented Mar 4, 2016

ping @asolove

@asolove
Copy link
Contributor Author

asolove commented Mar 4, 2016

I'm no longer working on the project this was intended for. Batch support is still a great idea for serious users of the FB API, but I don't have much insight into how to implement it, so I will just close this.

@asolove asolove closed this as completed Mar 4, 2016
@paulruescher
Copy link
Collaborator

paulruescher commented Oct 31, 2017

I was looking into this the other day, and if I have some free time I might dig into batch support. Is it possible to re-open this?

I think @tfinnell is working on implementing HTTPoison, so I wanted to check in and see if that's happening in the near-future. If so, I might hold off for a bit.

@tfinnell
Copy link
Collaborator

tfinnell commented Oct 31, 2017

I'll likely have a PR put together in the next few days as I get time to work more on it.

This would be interesting to implement and I'm wondering if it could be done without having to swap responses for requests, but rather intercept and rewrite the requests (exvcr is doing a similar interception I believe).

@paulruescher
Copy link
Collaborator

I'm sure we can do some pattern matching magic to accomplish this. I'll revisit some time next week. Going to spend a bit of time on one of my projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants