# Post.calculate\_avg\_time() taking up a long time

**URL:** https://meta.discourse.org/t/post-calculate-avg-time-taking-up-a-long-time/49750
**Category:** Support
**Created:** [2016 年 9 月 5 日午後 7:32 UTC](https://meta.discourse.org/t/post-calculate-avg-time-taking-up-a-long-time/49750 "2016-09-05T19:32:20Z")
**Posts on this page:** 1
**Showing post:** 13

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [2016 年 9 月 12 日午後 9:07 UTC](https://meta.discourse.org/t/post-calculate-avg-time-taking-up-a-long-time/49750/13 "2016-09-12T21:07:52Z")

</div>

> [@michaeld](#):
>
> daily

I believe the daily version of the query can be optimized by moving the filter up in the subquery.

Before: [kmV3 : Discourse Post.calculate\_avg\_time daily | explain.depesz.com](https://explain.depesz.com/s/kmV3)  
After: [i3JU : Discourse Post.calculate\_avg\_time daily Optimized | explain.depesz.com](https://explain.depesz.com/s/i3JU)

This would not apply to the weekly one, but as you stated the daily one is the bugger.

Can you try that and confirm the differences @michaeld ?

---

_[View the full topic](https://meta.discourse.org/t/post-calculate-avg-time-taking-up-a-long-time/49750)._
