Time to response

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: 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 query:

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
5 Likes