Skip to content

Commit

Permalink
New setting.py parameter: MINIO_BUCKET_EXISTENCE_CHECK_BEFORE_SAVE
Browse files Browse the repository at this point in the history
Checking the existence of our target bucket has a toll on overall performance, because the check itself is a call and if it's missing, the creation is another.
If the user is using static bucket names, then this action is an overkill and wastes execution time
  • Loading branch information
theriverman committed Mar 27, 2021
1 parent 4dd15a7 commit 5058fc4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions DjangoExampleProject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@
MINIO_POLICY_HOOKS: List[Tuple[str, dict]] = [
# ('django-backend-dev-private', dummy_policy)
]
MINIO_BUCKET_EXISTENCE_CHECK_BEFORE_SAVE = True # Create bucket if missing, then save
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ MINIO_PUBLIC_BUCKETS = [
'django-backend-dev-public',
]
MINIO_POLICY_HOOKS: List[Tuple[str, dict]] = []
MINIO_BUCKET_EXISTENCE_CHECK_BEFORE_SAVE = True # Default: True // Creates bucket if missing, then save
```

4. Implement your own Attachment handler and integrate **django-minio-backend**:
Expand Down
5 changes: 3 additions & 2 deletions django_minio_backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ def _save(self, file_path_name: str, content: InMemoryUploadedFile) -> str:
:param content (InMemoryUploadedFile): File object
:return:
"""
# Check if bucket exists, create if not
self.check_bucket_existence()
if get_setting("MINIO_BUCKET_EXISTENCE_CHECK_BEFORE_SAVE", True):
# Check if bucket exists, create if not
self.check_bucket_existence()

# Check if object with name already exists; delete if so
if self._REPLACE_EXISTING and self.stat(file_path_name):
Expand Down

0 comments on commit 5058fc4

Please sign in to comment.