Maintaining dynamically computed values in firebase
<p>I have a simple <strong>firebase</strong> database: <code>/rides</code> is a list of simple objects like this</p>

<pre><code>{
  car: "Toyota"
  minutes: 15
}
</code></pre>

<p>and I need to display sum of minutes of all the rides. The obvious solution is to load all the rides and calculate the sum. But if I have several hundreds of rides this is very slow, up to several seconds.</p>

<p>So it seems I have to maintain a separate field <code>/totalMinutes</code>in the database for this. But thus I will have to manually update <code>/totalMinutes</code> every time I add/remove/change a ride. Anyway this is not a big deal of work.</p>

<p>But what if I need to calculate total minutes only for a subset of rides? For instance only for "Toyota" cars or "Ford" cars? Manual maintaining <code>/totalMinutesFord</code>, <code>/totalMinutesToyota</code> now doesn't seem so easy.</p>

<p>So what is the correct way to maintain such dynamic values in <strong>firebase</strong>?</p>