Skip to content

Commit

Permalink
[IMP] fastapi: Simplified code and improved perfs
Browse files Browse the repository at this point in the history
The use of a BytesIO in place of our specialized SeekableStream class to keep the input stream in case we need to process the request again due to a retryable error outperforms both in terms of speed and memory consumption.

see OCA#440 (comment) for more info.
  • Loading branch information
lmignon committed Jun 28, 2024
1 parent 8b82ecd commit 1b0e0ad
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 190 deletions.
3 changes: 1 addition & 2 deletions fastapi/fastapi_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from fastapi.utils import is_body_allowed_for_status_code

from .context import odoo_env_ctx
from .seekable_stream import SeekableStream


class FastApiDispatcher(Dispatcher):
Expand Down Expand Up @@ -125,7 +124,7 @@ def _get_environ(self):
# from the stream. This way we can seek back to the beginning
# of the stream to read the data again if needed.
if not hasattr(httprequest, "_cached_stream"):
httprequest._cached_stream = SeekableStream(stream)
httprequest._cached_stream = BytesIO(stream.read())
stream = httprequest._cached_stream
stream.seek(0)
environ["wsgi.input"] = stream
Expand Down
101 changes: 0 additions & 101 deletions fastapi/seekable_stream.py

This file was deleted.

1 change: 0 additions & 1 deletion fastapi/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import test_fastapi
from . import test_fastapi_demo
from . import test_seekable_stream
86 changes: 0 additions & 86 deletions fastapi/tests/test_seekable_stream.py

This file was deleted.

0 comments on commit 1b0e0ad

Please sign in to comment.