Skip to content

Commit

Permalink
Merge pull request #73 from rok4/develop
Browse files Browse the repository at this point in the history
Release 2.0.1
  • Loading branch information
Dolite authored Oct 9, 2023
2 parents 9b6505e + 72ab76f commit b4281db
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: 2
updates:
- package-ecosystem: pip
directory: "/"
target-branch: develop
schedule:
interval: monthly
time: "17:00"
Expand All @@ -11,6 +12,7 @@ updates:

- package-ecosystem: "github-actions"
directory: "/"
target-branch: develop
schedule:
interval: monthly
time: "22:00"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
job_status: ${{ job.status }}
steps:
- name: Checkout project
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Create Release
id: create_release
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:

steps:
- name: Checkout project
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v4
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
steps:

- name: Checkout project on gh-pages
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: 'gh-pages'
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:

steps:
- name: Remove release and tag
uses: dev-drprasad/delete-tag-and-release@v0.2.0
uses: dev-drprasad/delete-tag-and-release@v1.0.1
with:
tag_name: ${{ github.ref_name }}
delete_release: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout project
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: 'gh-pages'
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -64,4 +64,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v2
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ repos:
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.281"
rev: "v0.0.291"
hooks:
- id: ruff
args: ["--fix-only", "--target-version=py38"]

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.9.1
hooks:
- id: black
args: ["--target-version=py38"]
Expand All @@ -40,7 +40,7 @@ repos:
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.13.0
hooks:
- id: pyupgrade
args:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2.0.1

### [Added]

* `storage` : le cache de lecture est configurable en taille (avec ROK4_READING_LRU_CACHE_SIZE) et en temps de rétention (avec ROK4_READING_LRU_CACHE_TTL)

### [Security]

* Montée de version de pillow (faille de sécurité liée à libwebp)

## 2.0.0

### [Fixed]
Expand Down
36 changes: 33 additions & 3 deletions src/rok4/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
According to functions, all storage types are not necessarily available.
Readings uses a LRU cache system with a TTL. It's possible to configure it with environment variables :
- ROK4_READING_LRU_CACHE_SIZE : Number of cached element. Default 64. Set 0 or a negative integer to configure a cache without bound. A power of two make cache more efficient.
- ROK4_READING_LRU_CACHE_TTL : Validity duration of cached element, in seconds. Default 300. 0 or negative integer to disable time validity.
To disable cache, set ROK4_READING_LRU_CACHE_SIZE to 1 and ROK4_READING_LRU_CACHE_TTL to 0.
Using CEPH storage requires environment variables :
- ROK4_CEPH_CONFFILE
- ROK4_CEPH_USERNAME
Expand Down Expand Up @@ -69,10 +75,34 @@
__S3_CLIENTS = {}
__S3_DEFAULT_CLIENT = None

__LRU_SIZE = 64
__LRU_TTL = 300

try:
__LRU_SIZE = int(os.environ["ROK4_READING_LRU_CACHE_SIZE"])
if __LRU_SIZE < 1:
__LRU_SIZE = None
except ValueError:
pass
except KeyError:
pass

try:
__LRU_TTL = int(os.environ["ROK4_READING_LRU_CACHE_TTL"])
if __LRU_TTL < 0:
__LRU_TTL = 0
except ValueError:
pass
except KeyError:
pass


def __get_ttl_hash():
"""Return the same value withing 5 minutes time period"""
return round(time.time() / 300)
"""Return the time string rounded according to time-to-live value"""
if __LRU_TTL == 0:
return time.time()
else:
return round(time.time() / __LRU_TTL)


def __get_s3_client(bucket_name: str) -> Tuple[Dict[str, Union["boto3.client", str]], str, str]:
Expand Down Expand Up @@ -294,7 +324,7 @@ def get_data_str(path: str) -> str:
return get_data_binary(path).decode("utf-8")


@lru_cache(maxsize=50)
@lru_cache(maxsize=__LRU_SIZE)
def __get_cached_data_binary(path: str, ttl_hash: int, range: Tuple[int, int] = None) -> str:
"""Load data into a binary string, using a LRU cache
Expand Down

0 comments on commit b4281db

Please sign in to comment.