public function get_contexts_to_reindex() {
        global $DB;

        list ($extrajoins, $dborder) = $this->get_contexts_to_reindex_extra_sql();
        $contexts = [];
        $selectcolumns = \context_helper::get_preload_record_columns_sql('x');
        $groupbycolumns = '';
        foreach (\context_helper::get_preload_record_columns('x') as $column => $thing) {
            if ($groupbycolumns !== '') {
                $groupbycolumns .= ',';
            }
            $groupbycolumns .= $column;
        }
        $rs = $DB->get_recordset_sql("
                SELECT $selectcolumns
                  FROM {course_modules} cm
                  JOIN {context} x ON x.instanceid = cm.id AND x.contextlevel = ?
                       $extrajoins
                 WHERE cm.module = (SELECT id FROM {modules} WHERE name = ?)
              GROUP BY $groupbycolumns
              ORDER BY $dborder", [CONTEXT_MODULE, $this->get_module_name()]);
        return new \core\dml\recordset_walk($rs, function($rec) {
            $id = $rec->ctxid;
            \context_helper::preload_from_record($rec);
            return \context::instance_by_id($id);
        });
    }