Skip to content

Commit

Permalink
Merge pull request #3941 from devos50/tc_stats_squash
Browse files Browse the repository at this point in the history
Reduced the number of requests to trustchain/statistics
  • Loading branch information
xoriole committed Oct 5, 2018
2 parents 9cfc6a6 + d74a3ac commit f26a7e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
10 changes: 7 additions & 3 deletions TriblerGUI/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,18 +527,22 @@ def on_token_balance_click(self, _):
self.raise_window()
self.deselect_all_menu_buttons()
self.stackedWidget.setCurrentIndex(PAGE_TRUST)
self.trust_page.load_trust_statistics()
self.load_token_balance()
self.trust_page.load_blocks()
self.navigation_stack = []
self.hide_left_menu_playlist()

def load_token_balance(self):
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("trustchain/statistics", self.received_token_balance, capture_errors=False)
self.request_mgr.perform_request("trustchain/statistics", self.received_trustchain_statistics,
capture_errors=False)

def received_token_balance(self, statistics):
def received_trustchain_statistics(self, statistics):
if not statistics or "statistics" not in statistics:
return

self.trust_page.received_trustchain_statistics(statistics)

statistics = statistics["statistics"]
if 'latest_block' in statistics:
balance = (statistics["latest_block"]["transaction"]["total_up"] -
Expand Down
18 changes: 4 additions & 14 deletions TriblerGUI/widgets/trustpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,31 @@ def __init__(self):
self.trust_plot = None
self.public_key = None
self.request_mgr = None
self.statistics = None
self.blocks = None
self.byte_scale = 1024 * 1024
self.refresh_timer = None

def initialize_trust_page(self):
vlayout = self.window().plot_widget.layout()
self.trust_plot = TrustPlotMplCanvas(self.window().plot_widget, dpi=100)
vlayout.addWidget(self.trust_plot)

self.refresh_timer = QTimer()
self.refresh_timer.timeout.connect(self.load_trust_statistics)
self.refresh_timer.start(60000)

self.window().trade_button.clicked.connect(self.on_trade_button_clicked)

def on_trade_button_clicked(self):
self.window().market_page.initialize_market_page()
self.window().navigation_stack.append(self.window().stackedWidget.currentIndex())
self.window().stackedWidget.setCurrentIndex(PAGE_MARKET)

def load_trust_statistics(self):
def load_blocks(self):
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("trustchain/statistics", self.received_trustchain_statistics)
self.request_mgr.perform_request("ipv8/trustchain/users/%s/blocks" % self.public_key,
self.received_trustchain_blocks)

def received_trustchain_statistics(self, statistics):
if not statistics:
return
statistics = statistics["statistics"]
self.public_key = statistics["id"]
total_up = 0
total_down = 0
if 'latest_block' in statistics:
Expand All @@ -124,12 +120,6 @@ def received_trustchain_statistics(self, statistics):
self.window().trust_people_helped_label.setText("%d" % statistics["peers_that_pk_helped"])
self.window().trust_people_helped_you_label.setText("%d" % statistics["peers_that_helped_pk"])

# Fetch the latest blocks of this user
self.public_key = statistics["id"]
self.request_mgr = TriblerRequestManager()
self.request_mgr.perform_request("ipv8/trustchain/users/%s/blocks" % self.public_key,
self.received_trustchain_blocks)

def received_trustchain_blocks(self, blocks):
if blocks:
self.blocks = blocks["blocks"]
Expand Down

0 comments on commit f26a7e3

Please sign in to comment.