Making Tables Faster

example table
<table>  <thead>    <th>User</th>    <th># Treated</th>    <th># Reached</th>    <th>Reach %</th>    <th># Accepted</th>    <th>Acceptance %</th>    <th>Accepted/Treated</th>    <th>Revenue </th>    <th>Cost </th>    <th>Profit</th>    <th>Profit %</th>  </thead>  <tbody>    <%= @users.each do |user| %>      <td><%= user.full_name %></td>      <td><%= user.leads.treated.size %></td>      <td><%= user.leads.reached.size %></td>      <td><%= user.leads.reached.size / user.leads.treated.size %></td>      <td><%= user.leads.accepted.size %></td>      <td><%= user.leads.accepted.size / user.leads.reached.size %></td>      <td><%= user.leads.accepted.size / user.leads.treated.size %></td>      <td><%= user.leads.sum(:revenue) %></td>      <td><%= user.leads.sum(:cost) %></td>      <td><%= user.leads.sum(:revenue) — user.leads.sum(:cost) %></td>      <td><%= (user.leads.sum(:revenue) — user.leads.sum(:cost)) / user.leads.sum(:revenue) %></td>    <% end %>  </tbody></table>
@full_names = User.all.pluck(:full_name).distinct@treated_leads = Leads.treated.joins(:user).group(‘users.full_name).count@reached_leads = Leads.reached.joins(:user).group(‘users.full_name).count@revenue = Leads.joins(:user).group(‘users.full_name).sum(:revenue)
...
etc.
<table>  <thead>    <th>User</th>    <th># Treated</th>    <th># Reached</th>    <th>Reach %</th>    <th># Accepted</th>    <th>Acceptance %</th>    <th>Accepted/Treated</th>    <th>Revenue </th>    <th>Cost </th>    <th>Profit</th>    <th>Profit %</th>  </thead>  <tbody>    <%= @full_names.each do |full_name| %>      <td><%= full_name %></td>      <td><%= @treated_leads[full_name] %></td>      <td><%= @reached_leads[full_name] %></td>      <td><%= @reached_leads[full_name] / @treated_leads[full_name] %></td>      <td><%= @accepted_leads[full_name] %></td>      <td><%= @accepted_leads[full_name] / @reached_leads[full_name] %></td>      <td><%= @accepted_leads[full_name] / @treated_leads[full_name %></td>      <td><%= @revenue[full_name] %></td>      <td><%= @cost[full_name] %></td>      <td><%= @revenue[full_name] — @cost[full_name] %></td>      <td><%= @(revenue[full_name] — @cost[full_name] ) / @revenue[full_name] %></td>    <% end %>  </tbody></table>
easy_data_tables github readme

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store