-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Timeout queue for posting updates #2
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from typing import Dict, List, Tuple, TypedDict, NamedTuple | ||
from typing import Dict, List, Tuple, TypedDict, NamedTuple, override | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
|
||
Property = NamedTuple("Property", [("name", str), ("value", str)]) | ||
|
||
|
@@ -11,7 +12,6 @@ class Page(TypedDict): | |
last_edited_time: str | ||
properties: Dict[str, Property] | ||
url: str | ||
|
||
|
||
class PropertyChange(TypedDict): | ||
"""Represents a change in a property | ||
|
@@ -28,9 +28,29 @@ class ChangeSet(): | |
"""Pages that were added in the diff""" | ||
removed: List[Page] | ||
"""Pages that were removed in the diff""" | ||
changed: List[Tuple[Page, List[PropertyChange]]] | ||
changed: Dict[str, Tuple[List[PropertyChange], datetime]] | ||
"""Pages that had their properties changed in the diff. The key is the page id and the value is the list of | ||
properties that were changed""" | ||
|
||
def is_empty(self) -> bool: | ||
return len(self.added) == 0 and len(self.removed) == 0 and len(self.changed) == 0 | ||
return self.added == [] and self.removed == [] and self.changed == {} | ||
|
||
def merge_set(self, other_changed_set): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add type annotations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How? It wont let me do typehint to ChangeSet |
||
"""merges the changes from the other set into the current set | ||
""" | ||
|
||
# For the added and removed pages, we simply add them to the new set if there is any | ||
self.added += other_changed_set.added | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this is not necessary since you don't have timeout to deal with for page additions/removals and therefore don't pass them forward to the next changeset There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do, because what we intend to do is always forward those into the master changeset, since our current logic is |
||
self.removed += other_changed_set.removed | ||
|
||
# For each change we check if its already in our dict | ||
for page_id, (propertyList, timestamp) in other_changed_set.changed.items(): | ||
if page_id in self.changed: | ||
property_changes, new_timestamp = self.changed[page_id] | ||
if timestamp > new_timestamp: | ||
new_timestamp = timestamp | ||
|
||
self.changed[page_id] = (propertyList + property_changes, new_timestamp) | ||
else: | ||
self.changed[page_id] = (propertyList, timestamp) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this docstring accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need anymore