Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Give every object in solitude an e-tag (bug 895172) #118

Merged
merged 1 commit into from Aug 7, 2013
Merged

Give every object in solitude an e-tag (bug 895172) #118

merged 1 commit into from Aug 7, 2013

Conversation

davidbgk
Copy link
Contributor

Still missing:

  • a validation about the epoch_micro approach
  • SQL queries to create the added field
  • a discussion about the situation of PUT/PATCH requests without an etag
  • a factorization of the code to extract mixins/resources dedicated to a given REST framework (note that UpdateModelMixin is not in use/tested for now)
  • switching to counter + pk as a unique etag


class ListModelMixin(object):
"""
Turns the django-rest-framework mixin into an etag-aware one.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of copypasta can we inherit and override methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, the granularity of the DRF doesn't allow to override just a method to deal with etags. I can inherit from the original mixin but the only method will be overridden so I think it's useless.

The support of etags in DRF is discussed in this issue (and a PR rejected by the maintainer)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, can the addition and validation of etags not be done by overriding finalize_response and initialize_request respectively, in the respective view classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a method that take a request and data (without performing the db request twice) and return a response to be able to use the etag decorator from Django. I preferred to modify the DRF at a higher level than to code my own etag decorator, this way I hope the switch to the future support of etags in DRF will be easier.

@wraithan
Copy link
Contributor

wraithan commented Aug 2, 2013

Looking good so far, ping me when you need another review on this.

@@ -3,4 +3,5 @@ DELETE FROM seller_product_bango;
DELETE FROM seller_product;
ALTER TABLE seller_product ADD COLUMN external_id varchar(255) NOT NULL;
ALTER TABLE seller_product ADD UNIQUE (`seller_id`, `external_id`);
ALTER TABLE `seller_product` ADD COLUMN `epoch_micro` bigint(20) NULL DEFAULT NULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add the column in an older migration otherwise 32-populate-public-id.py fails.

@davidbgk
Copy link
Contributor Author

davidbgk commented Aug 6, 2013

@andymckay having a counter indexed on epoch ms makes it easier to debug collisions. Is there any interest in storing the number of time an item is saved?

@andymckay
Copy link
Contributor

Should there be collisions? Everything in solitude is run in a transaction, so mysql should do all that work for us.

@davidbgk
Copy link
Contributor Author

davidbgk commented Aug 7, 2013

I just realized that the epoch_micro approach doesn't prevent from duplicates. I'll update with something based on counter + pk

@@ -1,17 +0,0 @@
import uuid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a comment to this file now

@andymckay
Copy link
Contributor

looks ok to me with use of F(), but would ask for @wraithan input too

@wraithan
Copy link
Contributor

wraithan commented Aug 7, 2013

has been summoned

r+wc, looks good to me with @andymckay's comments.

davidbgk added a commit that referenced this pull request Aug 7, 2013
Give every object in solitude an e-tag (bug 895172)
@davidbgk davidbgk merged commit 37aae81 into mozilla:master Aug 7, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants