private static function get_insert_batch_size(): int {
        global $DB;

        $dbconfig = $DB->export_dbconfig();

        // 500 is pgsql default so using 1000 is fine, no other db driver uses a hardcoded value.
        if (empty($dbconfig) || empty($dbconfig->dboptions) || empty($dbconfig->dboptions['bulkinsertsize'])) {
            return 1000;
        }

        $bulkinsert = $dbconfig->dboptions['bulkinsertsize'];
        if ($bulkinsert < 1000) {
            return $bulkinsert;
        }

        while ($bulkinsert > 1000) {
            $bulkinsert = round($bulkinsert / 2, 0);
        }

        return (int)$bulkinsert;
    }