boto3 S3 client accept a Prefix parameter that allow filtering S3 keys at the S3 api level, instead of fetching all items then filtering locally in python.
Originally created by @jcsaaddupuy on GitHub (Apr 15, 2025).
### Check Existing Issues
- [x] I have searched the existing issues and discussions.
### Problem Description
In [S3StorageProvider.delete_all_files](https://github.com/open-webui/open-webui/blob/main/backend/open_webui/storage/provider.py#L168-L182), all the files from the bucket are listed, then filtered in python on hte prefix.
`boto3` S3 client accept a `Prefix` parameter that allow filtering S3 keys at the S3 api level, instead of fetching all items then filtering locally in python.
instead of
```python
response = self.s3_client.list_objects_v2(Bucket=self.bucket_name)
```
we can do
```python
response = self.s3_client.list_objects_v2(Bucket=self.bucket_name, Prefix=self.key_prefix)
```
Let me know whaat you think, i'll gladly provide a PR for this change
### Desired Solution you'd like
Filtering S3 objects using the `list_objects_v2` `Prefix` parameter
```python
response = self.s3_client.list_objects_v2(Bucket=self.bucket_name, Prefix=self.key_prefix)
```
### Alternatives Considered
_No response_
### Additional Context
_No response_
@jcsaaddupuy commented on GitHub (Apr 15, 2025):
Hi !
I've started a fix here https://github.com/jcsaaddupuy/open-webui/tree/feat/12885-use-s3-prefix-parameter
I also started a discussion here https://github.com/open-webui/open-webui/discussions/12891 for follow up
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @jcsaaddupuy on GitHub (Apr 15, 2025).
Check Existing Issues
Problem Description
In S3StorageProvider.delete_all_files, all the files from the bucket are listed, then filtered in python on hte prefix.
boto3S3 client accept aPrefixparameter that allow filtering S3 keys at the S3 api level, instead of fetching all items then filtering locally in python.instead of
we can do
Let me know whaat you think, i'll gladly provide a PR for this change
Desired Solution you'd like
Filtering S3 objects using the
list_objects_v2PrefixparameterAlternatives Considered
No response
Additional Context
No response
@tjbck commented on GitHub (Apr 15, 2025):
PR welcome!
@jcsaaddupuy commented on GitHub (Apr 15, 2025):
Hi !
I've started a fix here https://github.com/jcsaaddupuy/open-webui/tree/feat/12885-use-s3-prefix-parameter
I also started a discussion here https://github.com/open-webui/open-webui/discussions/12891 for follow up