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

Optimise multiple queries in viewall students #52

Open
icyflame opened this issue Jun 11, 2015 · 4 comments
Open

Optimise multiple queries in viewall students #52

icyflame opened this issue Jun 11, 2015 · 4 comments

Comments

@icyflame
Copy link
Owner

https://github.com/icyflame/erp-rails/blob/master/app/views/viewall/students.html.erb#L28

@aniarya82
In this module, you are sending a query for each alumni ID. This is a very very network intensive operation. You should not calculate the count this way. You should calculate the count using the count feature in ActiveRecord. Fix this on an urgent basis.

@icyflame icyflame modified the milestone: Optimize the app to improve speed Jun 11, 2015
@icyflame
Copy link
Owner Author

@aniarya82
Solution

  1. maintain a counter for each student per response and per search (10 counter's total, Hash preferably)
  2. fetch all the alumni status records <- total queries = 1
  3. fetch all the tie records <- total queries = 2
  4. now, for each tie record :-
  • check the appropriate alumni status record (and increment the appropriate student's count)

This will solve the above problem in just 2 queries, as compared to the 2n queries you were using before. (n being the number of alumni in the DB)

@aniarya82
Copy link
Contributor

yeah i figured this as the only way out.

Anyways working on it..

All four issues expected to close by tomorrow.

On Fri, Jun 12, 2015 at 11:47 PM, Siddharth Kannan <[email protected]

wrote:

@aniarya82 https://github.com/aniarya82
Solution

  1. maintain a counter for each student per response and per search (10
    counter's total, Hash preferably)
  2. fetch all the alumni status records <- total queries = 1
  3. fetch all the tie records <- total queries = 2
  4. now, for each tie record :-
  • check the appropriate alumni status record (and increment the
    appropriate student's count)

This will solve the above problem in just 2 queries, as compared to the 2n
queries
you were using before. (n being the number of alumni in the DB)


Reply to this email directly or view it on GitHub
#52 (comment).

Regards,

Hiten Chowdhary

Undergraduate Student

Department of Mathematics

IIT Kharagpur

Ph: +919800111032

@icyflame
Copy link
Owner Author

@aniarya82
Sure!

icyflame added a commit that referenced this issue Jun 15, 2015
Optimize queries further.

- Using JOIN reduce everything to just one query.
- Work towards https://github.com/icyflame/erp-rails/milestones/Optimize%20the%20app%20to%20improve%20speed
- Currently only #52 is remainin g under this milestone.
@icyflame
Copy link
Owner Author

@aniarya82

The last PR #63 did not have any effect on the query scenario of the application. You need to spend some more time to close this out. (I have merged it because it improved the front end quite a bit)

@icyflame icyflame removed the URGENT label Jun 17, 2015
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

2 participants