public function get_first_post_for_discussion_ids(array $discussionids) : array {

        if (empty($discussionids)) {
            return [];
        }

        list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED);

        $sql = "
            SELECT p.*
              FROM {" . self::TABLE . "} p
              JOIN (
                SELECT mp.discussion, MIN(mp.created) AS created
                  FROM {" . self::TABLE . "} mp
                 WHERE mp.discussion {$insql}
              GROUP BY mp.discussion
              ) lp ON lp.discussion = p.discussion AND lp.created = p.created";

        return $this->get_db()->get_records_sql($sql, $params);
    }