# 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:** Product Support\
**Created:** [5 september 2016 om 19: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:** 26

<div class="post-metadata">

**Author:** ![kokmok](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kokmok/32/78954_2.png) [@kokmok](https://meta.discourse.org/u/kokmok)\
**Post date:** [5 mei 2019 om 17:37 UTC](https://meta.discourse.org/t/post-calculate-avg-time-taking-up-a-long-time/49750/26 "2019-05-05T17:37:07Z")

</div>

Is it possible that changes cause performance issue ?  
Our instance is running slow, and I had to cancel a query to get discourse running again (but still looks slow).  
The query is :

```
172 | 02:07:54.107363 | UPDATE posts +| active
| | SET avg_time = (x.gmean / 1000) +|
| | FROM (SELECT post_timings.topic_id, +|
| | post_timings.post_number, +|
| | round(exp(avg(CASE WHEN msecs > 0 THEN ln(msecs) ELSE 0 END))) AS gmean +|
| | FROM post_timings +|
| | INNER JOIN posts AS p2 +|
| | ON p2.post_number = post_timings.post_number +|
| | AND p2.topic_id = post_timings.topic_id +|
| | AND p2.user_id <> post_timings.user_id +|
| | WHERE (p2.topic_id IN (SELECT id FROM topics where bumped_at > '2019-05-03 09:39:22.717153'))+|
| | GROUP BY post_timings.topic_id, post_timings.post_number) AS x +|
| | WHERE (x.topic_id = posts.topic_id +|
| | AND x.post_number = posts.post_number +|
| | AND (posts.avg_time <> (x.gmean / 1000)::int OR posts.avg_time IS NULL)) |

```

We have a huge database with lots of topics containing 10k+ messages. We are trying to split them but cannot succeed to.

---

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