# 响应时间

**URL:** https://meta.discourse.org/t/time-to-response/120808
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [2019年六月19日 14:39 UTC](https://meta.discourse.org/t/time-to-response/120808 "2019-06-19T14:39:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jeanne\_Bertrand](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeanne_bertrand/32/144524_2.png) [@Jeanne\_Bertrand](https://meta.discourse.org/u/Jeanne_Bertrand)
#### Post date: [2019年六月19日 14:39 UTC](https://meta.discourse.org/t/time-to-response/120808/1 "2019-06-19T14:39:29Z")

</div>

Hi Discourse !

I was wondering how you calculate the time to first response in your reports.  
Based on what collection from your DB ?

Thank you for your time 🙂  
Jeanne

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2019年六月19日 19:35 UTC](https://meta.discourse.org/t/time-to-response/120808/2 "2019-06-19T19:35:52Z")

</div>

Time to first response is calculated by subtracting the value of the topic’s `created_at` field from the value of the `created_at` field of the topic’s first reply. The first reply is the first post in a topic that has a `post_number` greater than 1 and has a `post_type` of `1`. (a `post_type` of `1` is used to indicate that a post is a ‘regular’ post, and not a small action, moderator action, or whisper post.)

---

<div class="post-metadata">

### Author: ![Jeanne\_Bertrand](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeanne_bertrand/32/144524_2.png) [@Jeanne\_Bertrand](https://meta.discourse.org/u/Jeanne_Bertrand)
#### Post date: [2019年六月20日 14:20 UTC](https://meta.discourse.org/t/time-to-response/120808/3 "2019-06-20T14:20:36Z")

</div>

@simon thanks for your answer.  
I am using the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin. Do you know in what table I can find this field\_first reply ?  
I search for it but in vain ☹

Many thanks

Jeanne

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2019年六月20日 17:29 UTC](https://meta.discourse.org/t/time-to-response/120808/4 "2019-06-20T17:29:08Z")

</div>

> [@Jeanne\_Bertrand](#):
>
> I search for it but in vain

There isn’t a field in the database for this. Discourse uses a method that’s called on the `Topic` class to calculate the time to first response. You can see the code for it here: [discourse/app/models/topic.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/app/models/topic.rb#L1240).

This is approximately the SQL query that is generated by the `time_to_first_response` method. It can be run as a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query:

```sql
SELECT t.id AS topic_id, AVG(t.hours)::float AS hours, t.created_at
FROM (
  SELECT t.id, t.created_at::date AS created_at, EXTRACT(EPOCH FROM MIN(p.created_at) - t.created_at)::float / 3600.0 AS hours
  FROM topics t
  LEFT JOIN posts p ON p.topic_id = t.id
  WHERE t.archetype = 'regular'
  AND t.deleted_at IS NULL
  AND p.deleted_at IS NULL
  AND p.post_number > 1
  AND p.user_id != t.user_id
  AND p.post_type = 1
  GROUP BY t.id
) t
GROUP BY t.created_at, t.id
ORDER BY hours DESC

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2022年十二月31日 22:22 UTC](https://meta.discourse.org/t/time-to-response/120808/6 "2022-12-31T22:22:31Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
