Skip to content

Dashboard_helper Refactor

Charlie Martin edited this page Feb 2, 2016 · 4 revisions

The dashboard_helper makes queries to determine the number of measurements within a time segment, for each instrument. It is an expensive query because the measurement counts are grouped according to time identifier. This process is repeated three times, to get group counts by minute, hour and day.

The original dashboard_helper submitted a query for each individual instrument. If there were say 5 instruments, this created 15 queries. The code was refactored so that the same information was collected for all instruments, reducing the number of queries down to a constant 3.

This table presents the results, which were scraped from the Rails log. The log conveniently provides a summary of the total time, the time spent evaluating the view, and the time spent in the database access, for rendering of a page.

All times are in seconds, for the new method and the old method. You can see that the savings come from the database ActiveRecord access.

Portal Name Samples New Total Time Old Total Time New Views Time Old Views Time New AR Time Old AR Time
portal 0.68M 1.971 2.755 0.740 0.779 1.143 1.944
orcas 1.8M 3.895 6.790 0.731 0.785 3.044 6.045
3d 2.2M 6.995 24.76 1.117 0.950 5.761 23.757
Clone this wiki locally