def METHOD_NAME(response):
    user_agent = flask.request.headers.get('User-Agent', None)
    referrer = flask.request.referrer or None
    if is_spam(user_agent, referrer):
        return response
    lang_code = getattr(flask.g, '_lang_code', None)
    id = flask.request.args.get('id')
    cat = flask.request.args.get('cat')
    inter_id = flask.request.args.get('custom')
    url = flask.request.url
    prefetch = (flask.request.headers.get('purpose') == 'prefetch' or
                flask.request.headers.get('X-Moz') == 'prefetch')
    status_code = response.status_code
    with get_stats_db().cursor() as cursor, chdb.ignore_warnings():
        cursor.execute('INSERT INTO requests VALUES '
            '(NOW(), %s, %s, %s, %s, %s, %s, %s, %s)',
            (lang_code, id, cat, url, prefetch, status_code, referrer,
             inter_id))
    return response