Skip to content
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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

QuantumManiac
Copy link
Owner

No description provided.

classes.py Outdated
@@ -13,6 +14,11 @@ class Page(TypedDict):
url: str


def eq(self, other):
Copy link
Owner Author

Choose a reason for hiding this comment

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

TypedDicts can only contain type annotations. This can't be here, and I don't think it needs to be anyway.

"""

# For the added and removed pages, we simply add them to the new set if there is any
self.added += other_changed_set.added
Copy link
Owner Author

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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
get_new_changes -> merge_to_master -> check_timeout_at_master -> send_message_from_master

classes.py Outdated


# We compare if there are any changes in the same page and coalece
# Horribly underoptimized, we will get back to this later
Copy link
Owner Author

Choose a reason for hiding this comment

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

I agree. If you want to do this you should probably use a different data structure e.g. a dict that maps pages (or page IDs) to their changes

Copy link
Owner Author

Choose a reason for hiding this comment

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

suggestion: refactor Page into a dataclass so you can implement __hash__ and then change ChangeSet.changed into a Dict[Page, Tuple[List[PropertyChange], datetime]] or something

classes.py Outdated
@@ -12,6 +14,10 @@ class Page(TypedDict):
properties: Dict[str, Property]
url: str

@override
Copy link
Owner Author

Choose a reason for hiding this comment

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

Is @override necessary here? Does Page have a __hash__ method in the first place?

classes.py Outdated
@@ -12,6 +14,10 @@ class Page(TypedDict):
properties: Dict[str, Property]
url: str

@override
def __hash__(self) -> int:
return hash(page_id)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
return hash(page_id)
return hash(self.page_id)

@@ -28,9 +34,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[Page, 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
Copy link
Owner Author

Choose a reason for hiding this comment

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

Update this docstring accordingly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No need anymore

classes.py Outdated
# For each change we check if its already in our dict
for page, (propertyList, timestamp) in other_changed_set.changed:
if page in self.changed:
new_timestamp = self.changed[page][1]
Copy link
Owner Author

@QuantumManiac QuantumManiac Jul 11, 2024

Choose a reason for hiding this comment

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

Suggested change
new_timestamp = self.changed[page][1]
property_changes, new_timestamp = self.changed[page]

and then use property_changes on line 59

classes.py Outdated
self.removed += other_changed_set.removed

# For each change we check if its already in our dict
for page, (propertyList, timestamp) in other_changed_set.changed:
Copy link
Owner Author

Choose a reason for hiding this comment

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

Are you iterating through the dict here? If so,

Suggested change
for page, (propertyList, timestamp) in other_changed_set.changed:
for page, (propertyList, timestamp) in other_changed_set.changed.items():

"""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

def merge_set(self, other_changed_set):
Copy link
Owner Author

Choose a reason for hiding this comment

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

Add type annotations

Copy link
Collaborator

Choose a reason for hiding this comment

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

How? It wont let me do typehint to ChangeSet

@QuantumManiac QuantumManiac requested a review from Virulentis July 11, 2024 20:35
@PCModeActivate
Copy link
Collaborator

PCModeActivate commented Jul 12, 2024

Seems to be working now, but will need unit tested before we can merge. (https://discord.com/channels/1250426749058289715/1258870098790191234/1261162378268250244)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants