@action(route="/radiovis/api/<secret>/cleanup_logs")
@only_orga_admin_user()  # To prevent call from IO
@json_only()
def radiovis_api_cleanup_logs(request, secret):

    if secret != config.API_SECRET:
        abort(404)
        return

    # The following was not optimal thus replaced by RAW SQL
    # for object in LogEntry.query.filter(LogEntry.reception_timestamp < (time.time() - int(request.form.get('max_age')))).all():
    #     db.session.delete(object)
    #
    # db.session.commit()
    from sqlalchemy.sql import text
    db.engine.execute(text('DELETE FROM log_entry WHERE reception_timestamp <  :t'),
                      t = (time.time() - int(request.form.get('max_age'))))

    return {}
Cleanup logs if timestamp < time.time() - max_age
dataset/ETHPy150Open ebu/radiodns-plugit/RadioDns-PlugIt/radiovis/actions.py/radiovis_api_cleanup_logs