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

Refactored Credit Mining #3390

Merged
merged 1 commit into from
Feb 1, 2018
Merged

Conversation

egbertbouman
Copy link
Member

No description provided.

@egbertbouman egbertbouman force-pushed the credit_mining_devel branch 4 times, most recently from d075918 to a72200d Compare January 24, 2018 15:33
@egbertbouman egbertbouman changed the title WIP: Refactored CreditMining READY: Refactored CreditMining Jan 25, 2018
Copy link

@vandenheuvel vandenheuvel left a comment

Choose a reason for hiding this comment

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

Nice code, easy to understand. Also: love the total loc changes.

self.select_lc = self.register_task('select_torrents', LoopingCall(self.select_torrents))
self.session_ready = Deferred()

def initialize(self, policies=None):
Copy link

@vandenheuvel vandenheuvel Jan 26, 2018

Choose a reason for hiding this comment

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

Maybe you could merge this method with the __init__ method, developers may forget to initialize. And, isn't "init" short for "initialize"?


self.cancel_all_pending_tasks()

# shutil.rmtree(self.settings.save_path, ignore_errors=True)

Choose a reason for hiding this comment

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

Commented code

@qstokkink
Copy link
Contributor

@egbertbouman is this stable and ready for review?

@egbertbouman egbertbouman force-pushed the credit_mining_devel branch 4 times, most recently from b1c64b1 to f5dc2d3 Compare January 31, 2018 10:14
@egbertbouman
Copy link
Member Author

@qstokkink Yep, it's ready.

os.makedirs(self.settings.save_path)

self.select_lc = self.register_task('select_torrents', LoopingCall(self.select_torrents))
self.num_checkpoints = len(glob(os.path.join(self.session.get_downloads_pstate_dir(), '*.state')))
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this get the length of the path name?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it gets the number of checkpoints that we have on disk. I use this during startup to determine when the session if ready to receive credit mining downloads.

Copy link
Contributor

@devos50 devos50 left a comment

Choose a reason for hiding this comment

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

I really like the cleanup, good work! I have a few minor comments.

Minor comment: I usually add a line of comment above each test where I specify a bit what it exactly does. This human-readable string is visible when running the tests. On the other hand, I think the name of the test should also specify what it does so it might feel unnecessary. Anyway, it's a matter of personal preference whether to do this or not 👍

self.add_source(source)

self.session_ready = Deferred()
self.session_ready.addCallback(add_sources)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can go on one line?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right.

deferreds = []
if remove_downloads:
sources = self.sources.keys()
for source in sources:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe compress it to deferreds = [self.remove_source(source) for source in sources]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.


def add_source(self, source_str):
"""
Add new source into the credit mining manager
Copy link
Contributor

Choose a reason for hiding this comment

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

add a new source to the ...

if source_str not in self.sources:
num_torrents = len(self.torrents)

if isinstance(source_str, basestring) and len(source_str) == 40:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason to use basestring type instead of regular str?

Copy link
Member Author

Choose a reason for hiding this comment

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

I used basestring since that covers unicode as well.

@devos50
Copy link
Contributor

devos50 commented Jan 31, 2018

Don't forget to squash and rebase after you've answered/processed my comments :)

@devos50 devos50 changed the title READY: Refactored CreditMining Refactored CreditMining Feb 1, 2018
@devos50 devos50 changed the title Refactored CreditMining Refactored Credit Mining Feb 1, 2018
@devos50 devos50 merged commit 0e4103c into Tribler:devel Feb 1, 2018
@egbertbouman egbertbouman deleted the credit_mining_devel branch December 1, 2019 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants