Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: add compression support to frontend and backend #3549

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/backend/base/langflow/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import gzip
import json
import os
import warnings
Expand All @@ -12,7 +11,6 @@
import nest_asyncio # type: ignore
from fastapi import FastAPI, HTTPException, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.responses import FileResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from loguru import logger
Expand All @@ -30,11 +28,7 @@
)
from langflow.interface.types import get_and_cache_all_types_dict
from langflow.interface.utils import setup_llm_caching
from langflow.services.deps import (
get_cache_service,
get_settings_service,
get_telemetry_service,
)
from langflow.services.deps import get_cache_service, get_settings_service, get_telemetry_service
from langflow.services.plugins.langfuse_plugin import LangfuseInstance
from langflow.services.utils import initialize_services, teardown_services
from langflow.logging.logger import configure
Expand Down Expand Up @@ -138,21 +132,9 @@ def create_app():
allow_headers=["*"],
)
app.add_middleware(JavaScriptMIMETypeMiddleware)
app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=5)

# ! Deactivating this until we find a better solution
# app.add_middleware(RequestCancelledMiddleware)

@app.middleware("http")
async def decompress_if_gzip(request: Request, call_next):
if request.headers.get("content-encoding", "") == "gzip":
# the request's body is compressed, so we need to decompress it
body = await request.body()
dec = gzip.decompress(body)
request._body = dec # <-- if only things were that easy
response = await call_next(request)
return response

@app.middleware("http")
async def flatten_query_string_lists(request: Request, call_next):
flattened: list[tuple[str, str]] = []
Expand Down
7 changes: 0 additions & 7 deletions src/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"moment": "^2.30.1",
"openseadragon": "^4.1.1",
"p-debounce": "^4.0.0",
"pako": "^2.1.0",
"playwright": "^1.44.1",
"react": "^18.3.1",
"react-ace": "^11.0.1",
Expand Down
17 changes: 0 additions & 17 deletions src/frontend/src/controllers/API/api.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LANGFLOW_ACCESS_TOKEN } from "@/constants/constants";
import useAuthStore from "@/stores/authStore";
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from "axios";
import pako from "pako";
import { useContext, useEffect } from "react";
import { Cookies } from "react-cookie";
import { BuildStatus } from "../../constants/enums";
Expand All @@ -14,22 +13,6 @@ import { useLogout, useRefreshAccessToken } from "./queries/auth";
// Create a new Axios instance
const api: AxiosInstance = axios.create({
baseURL: "",
transformRequest: (axios.defaults.transformRequest
? Array.isArray(axios.defaults.transformRequest)
? axios.defaults.transformRequest
: [axios.defaults.transformRequest]
: []
).concat(function (data, headers) {
// compress strings if over 1KB
if (typeof data === "string" && data.length > 1024) {
headers["Content-Encoding"] = "gzip";
return pako.gzip(data);
} else {
// delete is slow apparently, faster to set to undefined
headers["Content-Encoding"] = undefined;
return data;
}
}),
});

const cookies = new Cookies();
Expand Down
Loading