Skip to content

Commit

Permalink
refactor: ota_proxy: use simple-sqlite3-orm instead of vendoring an o…
Browse files Browse the repository at this point in the history
…rm inside otaproxy package (#363)

This PR introduces to use simple-sqlite3-orm package(which is also implemented by me) instead. This package is feature-rich, well-implemented and well-tested replacement for the vendored sqlite3 ORM inside the otaproxy package.

Also this PR fixes a potential race condition, which the database entry being committed before the cache file being finalized, resulting small chance of cache file not found on database lookup hit.

Other major changes
* split cache_streaming related logic intocache_streaming module.
* split lru_cache_helper from ota_cache module into lru_cache_helper module.
* in lru_cache_helper, now we limit the max steps to walk down the bucket list when rotating the cache.
* in db, now we use RETURNING statement when rotating cache on supported platform.
* in ota_cache, now we also check db integrity to determine whether to force init.
  • Loading branch information
Bodong-Yang committed Aug 7, 2024
1 parent 9d62901 commit 3a96776
Show file tree
Hide file tree
Showing 13 changed files with 942 additions and 1,435 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"pyopenssl<25,>=24.1",
"pyyaml<7,>=6.0.1",
"requests<2.33,>=2.32",
"simple-sqlite3-orm @ https://github.com/pga2rn/simple-sqlite3-orm/releases/download/v0.2.0/simple_sqlite3_orm-0.2.0-py3-none-any.whl",
"typing-extensions>=4.6.3",
"urllib3<2.3,>=2.2.2",
"uvicorn[standard]<0.31,>=0.30",
Expand All @@ -45,7 +46,7 @@ optional-dependencies.dev = [
"flake8",
"isort",
"pytest==7.1.2",
"pytest-asyncio==0.21",
"pytest-asyncio==0.23.8",
"pytest-mock==3.14",
"requests-mock",
]
Expand All @@ -54,6 +55,9 @@ urls.Source = "https://github.com/tier4/ota-client"
[tool.hatch.version]
source = "vcs"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.hooks.vcs]
version-file = "src/_otaclient_version.py"

Expand Down
2 changes: 1 addition & 1 deletion src/ota_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from typing_extensions import ParamSpec, Self

from .cache_control import OTAFileCacheControl
from .cache_control_header import OTAFileCacheControl
from .config import config
from .ota_cache import OTACache
from .server_app import App
Expand Down
2 changes: 1 addition & 1 deletion src/ota_proxy/_consts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from multidict import istr

from .cache_control import OTAFileCacheControl
from .cache_control_header import OTAFileCacheControl

# uvicorn
REQ_TYPE_LIFESPAN = "lifespan"
Expand Down
File renamed without changes.
Loading

0 comments on commit 3a96776

Please sign in to comment.