{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-services/readinglist/pulls/comments/23383525","id":23383525,"diff_hunk":"@@ -24,3 +31,39 @@ def native_value(value):\n \n def Enum(**enums):\n     return type('Enum', (), enums)\n+\n+\n+class TimeStamper(object):\n+    \"\"\"A helper to generate accurate timestamps.\n+\n+    It increments a fraction in case prevent two simultaneous calls to return\n+    the same timestamp.\n+\n+    This is mainly used for in-memory backend. Ideally, this task should rely\n+    on storage backend transaction capabilities to guarantee timestamp unicity\n+    in a multiprocess environment.\n+\n+    .. note:\n+\n+        Original comes from http://stackoverflow.com/a/157711\n+    \"\"\"\n+    fraction = decimal.Decimal('0.001')\n+\n+    def __init__(self):\n+        self.lock = threading.Lock()","path":"readinglist/utils.py","position":42,"original_position":42,"commit_id":"ad5dd86ce5ac0998bb00f53c90795a746c9b687e","original_commit_id":"ad5dd86ce5ac0998bb00f53c90795a746c9b687e","user":{"login":"tarekziade","id":250019,"avatar_url":"https://avatars.githubusercontent.com/u/250019?v=3","gravatar_id":"","url":"https://api.github.com/users/tarekziade","html_url":"https://github.com/tarekziade","followers_url":"https://api.github.com/users/tarekziade/followers","following_url":"https://api.github.com/users/tarekziade/following{/other_user}","gists_url":"https://api.github.com/users/tarekziade/gists{/gist_id}","starred_url":"https://api.github.com/users/tarekziade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tarekziade/subscriptions","organizations_url":"https://api.github.com/users/tarekziade/orgs","repos_url":"https://api.github.com/users/tarekziade/repos","events_url":"https://api.github.com/users/tarekziade/events{/privacy}","received_events_url":"https://api.github.com/users/tarekziade/received_events","type":"User","site_admin":false},"body":"this lock can't work on a server app because we might deploy several processes behind nginx. ","created_at":"2015-01-22T15:37:32Z","updated_at":"2015-01-22T15:37:32Z","html_url":"https://github.com/mozilla-services/readinglist/pull/57#discussion_r23383525","pull_request_url":"https://api.github.com/repos/mozilla-services/readinglist/pulls/57","_links":{"self":{"href":"https://api.github.com/repos/mozilla-services/readinglist/pulls/comments/23383525"},"html":{"href":"https://github.com/mozilla-services/readinglist/pull/57#discussion_r23383525"},"pull_request":{"href":"https://api.github.com/repos/mozilla-services/readinglist/pulls/57"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla-services/readinglist/pulls/57","id":27850804,"html_url":"https://github.com/mozilla-services/readinglist/pull/57","diff_url":"https://github.com/mozilla-services/readinglist/pull/57.diff","patch_url":"https://github.com/mozilla-services/readinglist/pull/57.patch","issue_url":"https://api.github.com/repos/mozilla-services/readinglist/issues/57","number":57,"state":"open","locked":false,"title":"Switch to vector-clock timestamps (fixes #4)","user":{"login":"leplatrem","id":546692,"avatar_url":"https://avatars.githubusercontent.com/u/546692?v=3","gravatar_id":"","url":"https://api.github.com/users/leplatrem","html_url":"https://github.com/leplatrem","followers_url":"https://api.github.com/users/leplatrem/followers","following_url":"https://api.github.com/users/leplatrem/following{/other_user}","gists_url":"https://api.github.com/users/leplatrem/gists{/gist_id}","starred_url":"https://api.github.com/users/leplatrem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leplatrem/subscriptions","organizations_url":"https://api.github.com/users/leplatrem/orgs","repos_url":"https://api.github.com/users/leplatrem/repos","events_url":"https://api.github.com/users/leplatrem/events{/privacy}","received_events_url":"https://api.github.com/users/leplatrem/received_events","type":"User","site_admin":false},"body":"Avoid races using vector-clock timestamps, as described in #4 : \r\n\r\n```\r\nClient A: [        fetch                 ] t = 1234\r\nClient B:                     [insert] t = 1230\r\nClient A:                                           [fetch since t=1234] t=1345\r\n```\r\n\r\nBasically, a naive approach: \r\n* build millisecond timestamps with incremented fraction\r\n* each incoming request has a different timestamp (even if less than 1msec of difference)\r\n* ``last_modified`` is assigned with this request timestamp\r\n* request timestamp is provided in request response\r\n\r\nTo be improved/reviewed/discussed:\r\n* Filter ``_since`` is exclusive (strictly greater ``>``)\r\n* ``stored_on`` is not receiving the same value as ``last_modified``\r\n* Implementation of timestamping shall be implemented by storage backend (guarantee timestamp unicity in *multiprocess* environment)","created_at":"2015-01-22T15:30:51Z","updated_at":"2015-01-22T15:37:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab67a51640b748d845c23f1b6f6b8037f16a8a3c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-services/readinglist/pulls/57/commits","review_comments_url":"https://api.github.com/repos/mozilla-services/readinglist/pulls/57/comments","review_comment_url":"https://api.github.com/repos/mozilla-services/readinglist/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla-services/readinglist/issues/57/comments","statuses_url":"https://api.github.com/repos/mozilla-services/readinglist/statuses/ad5dd86ce5ac0998bb00f53c90795a746c9b687e","head":{"label":"mozilla-services:4-vector-clock-timestamps","ref":"4-vector-clock-timestamps","sha":"ad5dd86ce5ac0998bb00f53c90795a746c9b687e","user":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"repo":{"id":27563721,"name":"readinglist","full_name":"mozilla-services/readinglist","owner":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-services/readinglist","description":"Reading List Server","fork":false,"url":"https://api.github.com/repos/mozilla-services/readinglist","forks_url":"https://api.github.com/repos/mozilla-services/readinglist/forks","keys_url":"https://api.github.com/repos/mozilla-services/readinglist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-services/readinglist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-services/readinglist/teams","hooks_url":"https://api.github.com/repos/mozilla-services/readinglist/hooks","issue_events_url":"https://api.github.com/repos/mozilla-services/readinglist/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-services/readinglist/events","assignees_url":"https://api.github.com/repos/mozilla-services/readinglist/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-services/readinglist/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-services/readinglist/tags","blobs_url":"https://api.github.com/repos/mozilla-services/readinglist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-services/readinglist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-services/readinglist/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-services/readinglist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-services/readinglist/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-services/readinglist/languages","stargazers_url":"https://api.github.com/repos/mozilla-services/readinglist/stargazers","contributors_url":"https://api.github.com/repos/mozilla-services/readinglist/contributors","subscribers_url":"https://api.github.com/repos/mozilla-services/readinglist/subscribers","subscription_url":"https://api.github.com/repos/mozilla-services/readinglist/subscription","commits_url":"https://api.github.com/repos/mozilla-services/readinglist/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-services/readinglist/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-services/readinglist/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-services/readinglist/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla-services/readinglist/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-services/readinglist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-services/readinglist/merges","archive_url":"https://api.github.com/repos/mozilla-services/readinglist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-services/readinglist/downloads","issues_url":"https://api.github.com/repos/mozilla-services/readinglist/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-services/readinglist/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-services/readinglist/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-services/readinglist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-services/readinglist/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-services/readinglist/releases{/id}","created_at":"2014-12-04T22:48:28Z","updated_at":"2015-01-22T12:19:25Z","pushed_at":"2015-01-22T15:29:12Z","git_url":"git://github.com/mozilla-services/readinglist.git","ssh_url":"git@github.com:mozilla-services/readinglist.git","clone_url":"https://github.com/mozilla-services/readinglist.git","svn_url":"https://github.com/mozilla-services/readinglist","homepage":null,"size":1728,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":36,"forks":0,"open_issues":36,"watchers":3,"default_branch":"master"}},"base":{"label":"mozilla-services:master","ref":"master","sha":"05bfa6a84bc7a7b3e363008c887a4387f11c51f9","user":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"repo":{"id":27563721,"name":"readinglist","full_name":"mozilla-services/readinglist","owner":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-services/readinglist","description":"Reading List Server","fork":false,"url":"https://api.github.com/repos/mozilla-services/readinglist","forks_url":"https://api.github.com/repos/mozilla-services/readinglist/forks","keys_url":"https://api.github.com/repos/mozilla-services/readinglist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-services/readinglist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-services/readinglist/teams","hooks_url":"https://api.github.com/repos/mozilla-services/readinglist/hooks","issue_events_url":"https://api.github.com/repos/mozilla-services/readinglist/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-services/readinglist/events","assignees_url":"https://api.github.com/repos/mozilla-services/readinglist/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-services/readinglist/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-services/readinglist/tags","blobs_url":"https://api.github.com/repos/mozilla-services/readinglist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-services/readinglist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-services/readinglist/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-services/readinglist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-services/readinglist/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-services/readinglist/languages","stargazers_url":"https://api.github.com/repos/mozilla-services/readinglist/stargazers","contributors_url":"https://api.github.com/repos/mozilla-services/readinglist/contributors","subscribers_url":"https://api.github.com/repos/mozilla-services/readinglist/subscribers","subscription_url":"https://api.github.com/repos/mozilla-services/readinglist/subscription","commits_url":"https://api.github.com/repos/mozilla-services/readinglist/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-services/readinglist/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-services/readinglist/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-services/readinglist/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla-services/readinglist/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-services/readinglist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-services/readinglist/merges","archive_url":"https://api.github.com/repos/mozilla-services/readinglist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-services/readinglist/downloads","issues_url":"https://api.github.com/repos/mozilla-services/readinglist/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-services/readinglist/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-services/readinglist/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-services/readinglist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-services/readinglist/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-services/readinglist/releases{/id}","created_at":"2014-12-04T22:48:28Z","updated_at":"2015-01-22T12:19:25Z","pushed_at":"2015-01-22T15:29:12Z","git_url":"git://github.com/mozilla-services/readinglist.git","ssh_url":"git@github.com:mozilla-services/readinglist.git","clone_url":"https://github.com/mozilla-services/readinglist.git","svn_url":"https://github.com/mozilla-services/readinglist","homepage":null,"size":1728,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":36,"forks":0,"open_issues":36,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-services/readinglist/pulls/57"},"html":{"href":"https://github.com/mozilla-services/readinglist/pull/57"},"issue":{"href":"https://api.github.com/repos/mozilla-services/readinglist/issues/57"},"comments":{"href":"https://api.github.com/repos/mozilla-services/readinglist/issues/57/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-services/readinglist/pulls/57/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-services/readinglist/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla-services/readinglist/pulls/57/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-services/readinglist/statuses/ad5dd86ce5ac0998bb00f53c90795a746c9b687e"}}}}