Skip to content

[WIP] Timeout queue for posting updates#2

Draft
QuantumManiac wants to merge 4 commits into
mainfrom
timeout_queue_dev
Draft

[WIP] Timeout queue for posting updates#2
QuantumManiac wants to merge 4 commits into
mainfrom
timeout_queue_dev

Conversation

@QuantumManiac

Copy link
Copy Markdown
Owner

No description provided.

Comment thread classes.py Outdated
url: str


def eq(self, other):

Copy link
Copy Markdown
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.

Comment thread classes.py
"""

# 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
Copy Markdown
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
Copy Markdown
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

Comment thread 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
Copy Markdown
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
Copy Markdown
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

Comment thread classes.py Outdated
properties: Dict[str, Property]
url: str

@override

Copy link
Copy Markdown
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?

Comment thread classes.py Outdated

@override
def __hash__(self) -> int:
return hash(page_id)

Copy link
Copy Markdown
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)

Comment thread classes.py
"""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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need anymore

Comment thread 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]

@QuantumManiac QuantumManiac Jul 11, 2024

Copy link
Copy Markdown
Owner Author

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

Comment thread 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
Copy Markdown
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():

Comment thread classes.py
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
Copy Markdown
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
Copy Markdown
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

PCModeActivate commented Jul 12, 2024

Copy link
Copy Markdown
Collaborator

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