WordPress JSON API for mobile app. Response time very slow - ios

i am currently using the WordPress JSPON API plugin to feed my mobile iOS application with content from the blog.
However the response time to load some posts inside the app is very slow and i am now looking to find a way to optimize it.
I read about the transients API but not sure if this will be the right thing for it and also i donĀ“t know how exactly to integrate this with the JSON API Plugin to get better response times?
Currently to fetch 10 Posts takes about 7-8 seconds (remote)
strURl=[NSString stringWithFormat:#"%#get_recent_posts/?page=%i&dev=1",mainURL,page];
Locally this takes about less then a second.
Now can anyone tell me what to do here?

Related

Stream executing log to Objective-C

I am building an app for Jenkins CI and need to display a log like this: https://ci.jenkins-ci.org/job/infra_backend_pull_request_greeter/lastBuild/consoleText in the app. That is simple, the trouble comes when the CI server is actually executing the job and the lines are coming, the web browser is displaying the partial data as they come but how do I do that on the iPhone without having to reload the entire thing ... there has to be some streaming or something?
For the API I am using AFNetworking so would be great if you'd knew how to do that using that but any solution will be much appreciated.

Caching( optimizing) Strategy with API live stream on Rails

So I built a website that uses Twitch.tv API, which is a gaming live stream website. The requests are long and slow, and I would like to cache it somehow. The problem is that there are a lot of dynamic attributes, if they are still online, or how many viewers there are. Since the traffic to my website is low at the moment, expiring Cache early isn't going to help much. Also, I have a page where it lists all the live streams, and it requests to see if the stream is online. So even if no one is online it still takes a while to load. Is there anyway to retrieve api faster without caching?
here is twitch.tv api doc
Since you don't own the Twitch.tv API, unfortunately I would say there is really nothing you can do to make their calls faster.
The good news is that you can cache the calls you make to them, which will make things appear faster to your users.
The way to cache the calls is to create a key and then cache the return JSON from the API. To create the key I would just use the URL you are calling for the API. Then just give the cached value an expiration time of a few minutes and when it expires you make another API call to re-populate the cache.
Also I'd look at Varnish (https://www.varnish-cache.org/) which does a lot of HTTP caching really well. Could work really well for you and it has the concept of a grace period that tries to hide the expensive calls made when the cache expires.

Twitter Ruby Gem Too many requests

I'm currently using TDD with rspec and Ruby on Rails (with twitter gem) to pull tweets and trends for analytics. However, I constantly get Twitter::Error::TooManyRequests and have to sit around twiddling thumbs till I can make another request. Is this a limitation of Twitter search API or am I doing something wrong?
Right now I have a simple index page that invokes Twitter.config once and follows it with Twitter.trends once. Running rspec spec on this to generate one index page results in the previously mentioned error. Am I missing something here? I can't find anywhere (application, framework, or full traces) where the twitter requests are made in abundance.
I'm not using the stream API just yet because it only provides raw tweets and not trending information.
Twitter has a rate limit of something like 150 requests when not authenticated and 250 requests for authenticated users.
Perhaps you could figure a way to gather your data in chunks instead of constant calls.
You may want check out the VCR gem which can record HTTP interactions so that you're not continually hitting the external service.

Accessing shared DB using iOS and Django

I'm just starting to learn about iOS development, and I figure the best way to get started is to build a simple (but non-trivial) app. My idea is this: have a web interface where a user can create a survey, and then access those surveys through the app and send responses back to the server. The web design part probably won't be terribly difficult -- I've done similar things with Django before. The part that will require learning/effort is the iPhone app.
I've got enough Objective-C that the data structures (model) won't be hard to code, and the UI (view, controller) part shouldn't be bad either. I predict that the interface between web and phone will be difficult, though. In particular, how will I be able to access the database on the server from the phone? I'd like to have a single DB that both web and phone apps use.
What I'd really like to have is a general, broad-strokes description of what I'll need to do to get this all up and running. Am I right in believing that the networking will be the hardest part? Are there any other possible snags? Any advice, or pointers to good resources on the subject, would be greatly appreciated.
Networking will probably not be the hardest part here, you're just guessing because that aspect is unfamiliar to you. For example, you can use NSURLConnection to take care of pretty much all the details of server connection. You can use NSJSONSerialization to convert your data to and from a format that is suitable for sending over the wire.
Basically what you might do is:
Mobile app sends a HTTP GET request to the server for survey info.
Server responds with a JSON description of the survey.
User fills out survey.
When done, the app sends the responses back in JSON format as a HTTP POST to the server.
Server stores the results in the database.
One of the key points here is that the app on the phone does not try to access the database directly. All requests go through your Django web app.

Posting multipart form data with Ruby

I'm building a rails app that interacts with a 3rd party API
When a user uploads a file to rails, it should be forwarded on to the 3rd party site via an HTTP POST.
In some cases, the upload can be several hundred MBs.
At the moment, I've just been re-posting to the API using Net::HTTP and accessing the multipart form object like so
#tempfile = params[:video][:file_upload].tempfile
This is hella slow though and feels kinda dirty.
Is there a better way to do this?
Is it possible to have the user post directly to the 3rd party service or do you have to handle the API through your Rails stack? Ideally you would be able to do this and would not have to load the file into your stack and then re-post it to the API. If you can't post directly, I would recommend seeing if the API has a streaming service so that you can send parts of the file instead of the entire thing at once. Either way I think you'll start running into Timeout errors on your side and on the API side with large files, so you'll have to increase your own timeouts or create a different type of streaming file uploader.
Spin up a background job using DelayedJob. In the delayed job, you could try rails redirect_to.
https://github.com/tobi/delayed_job
http://apidock.com/rails/ActionController/Base/redirect_to

Resources