WikiEducationFoundation / WikiEduDashboard

Wiki Education Foundation's Wikipedia course dashboard system
https://dashboard.wikiedu.org
MIT License
392 stars 630 forks source link

[Not urgent] Add Pagination in Uploads API. #2996

Closed ujjwalagrawal17 closed 3 years ago

ujjwalagrawal17 commented 5 years ago

in Some courses like https://outreachdashboard.wmflabs.org/courses/WMFr/EDITATHONS_2017/uploads.json ,the uploads API is taking a lot of time to give response [this course has around 500 images]. We can implement pagination in the API to give results by using parameter page_number.

ANURADHAJHA99 commented 5 years ago

@ujjwalagrawal17 I would like to work on this issue. KIndly assign this to me.

ujjwalagrawal17 commented 5 years ago

@anuradhajha99 feel free to start working on it. We will use this in the Android app after it's ready.

ANURADHAJHA99 commented 5 years ago

@ujjwalagrawal17 KIndly help me if I am wrong. But I visited the website https://outreachdashboard.wmflabs.org/courses/WMFr/EDITATHONS_2017/uploads and the uploads section already had the pagination. Can you kindly explain how should I start with the issue? Thank you very much.

ujjwalagrawal17 commented 5 years ago

I guess the support in web version is added but in https://outreachdashboard.wmflabs.org/courses/WMFr/EDITATHONS_2017/uploads.json API it's not added. We need to add the required parameters to make it work.

ujjwalagrawal17 commented 5 years ago

We are consuming the API from Android App and in some courses we are getting very slow response.

ANURADHAJHA99 commented 5 years ago

@ujjwalagrawal17 Thank you very much. however, can you give me an idea of how should I start with the issue, what steps should I start taking, what files do I need to change? It will be very helpful.

ujjwalagrawal17 commented 5 years ago

@ragesoss might be able to help you in that. I am not familiar with the website codebase.

ANURADHAJHA99 commented 5 years ago

@ragesoss Can you please guide me through the following issue? Also, Thank you very much @ujjwalagrawal17 for helping.

ragesoss commented 5 years ago

The uploads endpoint is CoursesController#uploads, which basically just finds the course and then immediately renders the corresponding view, app/views/courses/uploads.json.jbuilder.

The most similar place where you can find an example of pagination already in use is CampaignsController, which sets the page from the query parameters, and then uses the will_paginate gem to get the page-based query results in the 'articles' and 'programs' views. The same strategy should work here, but for CoursesController#uploads we would need to either only paginate if the page param is there (so that the web version maintains the current behavior), or also update the website frontend to use the pagination. Currently, we just have client-side pagination on the web, so it requests and stores the full set of uploads data, and then only renders one page at a time but does not make additional requests to the server.

ANURADHAJHA99 commented 5 years ago

@ragesoss Can you please navigate me to the CampaignsController code to understand the context? I am having some difficulty in understanding the codebase.

ragesoss commented 5 years ago

CampaignsController is in app/controllers/campaigns_controller.rb. It's responsible for handling web requests to main 'campaigns' views, such as https://dashboard.wikiedu.org/campaigns/fall_2018/programs

If you're unfamiliar with Ruby on Rails, I suggest starting by exploring the Rails documentation a bit to see how models, views, and controllers interact.

ANURADHAJHA99 commented 5 years ago

@ragesoss we have to find the page param from the URL and use the will_paginate gem if the param is present? am I following the correct way? Thank you for the feedback.

ragesoss commented 5 years ago

Yes, I think so.

ANURADHAJHA99 commented 5 years ago

Going by the campaign_controller.rb, I came across various dependencies, What are the required dependencies to make the course-controller, that will extract the URL and then the page param from the dependencies? Screenshot from 2019-10-25 22-18-02

ragesoss commented 5 years ago

Rails provides all request parameters via params, which is basically just a hash.

This controller uses the set_page method to set an instance variable from that param, and the instance variable can then be used in the view template that gets rendered.

ANURADHAJHA99 commented 5 years ago

Am I supposed to make another view for the uploads, just like article and programs in the campaign controller, because I have set the params of the page in course-controller but I cannot find uploads.haml which is used to render as a view?

ragesoss commented 5 years ago

For courses controller, it uses a json jbuilder view template instead of an html haml template. This app/view/courses/uploads.json.builder.

tafodinho commented 4 years ago

Hi, @ragesoss. Was this issue successfully solved?? if not I would love to get right on itas my first contribution.

ANURADHAJHA99 commented 4 years ago

@tafodinho I had various problems while solving the following issue. You can refer to the pull requests that I made, to understand the errors. Thank you for taking the following issue. I am sorry I could not work due to the lack of knowledge and time.

tafodinho commented 4 years ago

okay @ANURADHAJHA99 let me take a look right now

ciphereck commented 4 years ago

hi @tafodinho are you still working on this? @ragesoss is the issue still open?

ragesoss commented 4 years ago

Yes, it's still open.

ciphereck commented 4 years ago

@ragesoss okay I'm starting to work on it

ciphereck commented 4 years ago

I'm still working on it. Just getting to know the codebase and setting up the development environment. Reached till populating the database.

ciphereck commented 4 years ago

@ragesoss I have an issue My http://localhost:3000/courses/ab/ab/uploads.json returns {"course":{"uploads":[]}} Idk how to populate data in upload array to check my pagination Can you please tell me how to populate data in this uploads array in the database?

ciphereck commented 4 years ago

@ujjwalagrawal17 @ragesoss Can you please tell me how many entries we want on a page? For 10 entries, the INFO says it completed in 10ms and for 193 entries, it says it completed in 40ms

I think 10 is fine for android because android has less screen space (shorter screen size).

ujjwalagrawal17 commented 4 years ago

Yes 10 is fine. If you can add another variable to make it configurable, it will be great.

ciphereck commented 4 years ago

Sure, I can add another variable.

ciphereck commented 4 years ago

I added another variable and updated the PR. Can you please check if it's working fine as required. Also, it failed Travis build with the first commit. I can't figure out why.

ragesoss commented 4 years ago

The build problem was unrelated (and now fixed on master)... it looks like this doesn't break any tests that weren't already broken. It's probably ready to go once it has a spec to exercise the pagination functionality.

ragesoss commented 3 years ago

Closing this, since the phone app isn't under activity development.