Skip to content

Storages behaviour is not optimal #17

@Aramgutang

Description

@Aramgutang

There are numerous issues with the way storages are set up in ixc-django-docker.

For starters, this:

AWS_HEADERS = {
'Expires': 'Thu, 31 Dec 2099 00:00:00 GMT',
'Cache-Control': 'max-age=86400',
}

Per the current django-storages docs, that actually has no effect, since it's only used with boto, not boto3, and we use the latter.

The suggested way to define a never-expire cache instead is via object parameters (also note the use of a properly large max-age):

AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=31536000',
    'Expires': datetime(2099, 12, 31),
}

However, I would hesitate to use that, as it would be the default for all uploads, not just those that use unique filenames, and we probably only want to use it when using unique filename storage. It would probably be best to add a new mixin:

class S3CacheForever(object):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('object_parameters', {
            'CacheControl': 'max-age=31536000',
            'Expires': datetime(2099, 12, 31),
        })
        super(S3CacheForever, self).__init__(*args, **kwargs)

And then add that to the list of mixins when constructing the unique storages:

class S3UniquePrivateStorage(
UniqueMixin,
S3GetContentHashMixin,
S3MediaLocationMixin,
S3PrivateMixin,
S3BotoStorage):
pass
class S3UniquePublicStorage(
UniqueMixin,
S3GetContentHashMixin,
S3MediaLocationMixin,
S3PublicMixin,
S3BotoStorage):
pass

Speaking of the list of mixins above, note UniqueMixin followed by S3GetContentHashMixin. The only functionality the latter provides is an overridden get_content_hash() method. However, UniqueMixin also overrides get_content_hash(), and doesn't call super() within it, so the functionality of S3GetContentHashMixin is never invoked. I'm not sure what the history of that mixin is and what it's trying to accomplish, so I don't have any specific suggestions other than for someone with more contextual knowledge to review the situation and either make its functionality invokable, or remove it altogether.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions