Skip to content

Conversation

@dgarros
Copy link
Contributor

@dgarros dgarros commented Oct 9, 2020

fixes #12

This PR restructure the get_children method in the Diff object to leverage new order_children methods.
By default get_children will check if a order_children method specific to each children is available (order_children_site for site) or call the order_children_default.

Each order_children method needs to return an Iterator of DiffElement and get_children is returning a global iterator with all children.

Here is an example on how to order the sites in alphabetical order

class MyDiff(Diff):

    @classmethod
    def order_children_site(cls, children) ->  Iterator["DiffElement"]:
       """Return the site children ordered in alphabetical order."""
       keys = sorted(children.keys(), reverse=False)
        for key in keys:
            yield children[key]

a = BackendA()
a.load()

b = BackendB()
b.load()

diff_a_b = a.diff_to(b, diff_class=MyDiff)

Base automatically changed from gfm-issue-6 to master October 9, 2020 12:13
Copy link
Collaborator

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

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

With the API restructuring made in #10, would it be more consistent (and make any sense) to make the ordering into a method on the individual DSyncModel subclasses instead of a method of the DSync class? Maybe even let the DSyncModels define __lt__ and __eq__ and use sorted(self.children[group])? Just thinking aloud here.

@dgarros
Copy link
Contributor Author

dgarros commented Oct 9, 2020

With the API restructuring made in #10, would it be more consistent (and make any sense) to make the ordering into a method on the individual DSyncModel subclasses instead of a method of the DSync class? Maybe even let the DSyncModels define __lt__ and __eq__ and use sorted(self.children[group])? Just thinking aloud here.

I thought about it too but since the ordering is currently happening in the Diff object I don't think we can have access to the DSyncModel within the get_children method, please let me know if I'm missing something.

@dgarros dgarros marked this pull request as ready for review October 12, 2020 19:48
@glennmatthews glennmatthews merged commit 123397b into master Oct 13, 2020
@glennmatthews glennmatthews deleted the dga-issue-12 branch October 23, 2020 19:20
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.

Control the order in which objects are created/updated/deleted during a sync

3 participants