URI: 
       twallet: cache NaN coin prices, clear cache on new history - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 863ee984fee7931c94467c92934caf19f2ec1949
   DIR parent ee287740a7eeed9b40cfdd85d967009bbbb882ee
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Thu, 29 Nov 2018 20:47:26 +0100
       
       wallet: cache NaN coin prices, clear cache on new history
       
       Diffstat:
         M electrum/gui/kivy/main_window.py    |       1 +
         M electrum/gui/qt/main_window.py      |       1 +
         M electrum/wallet.py                  |      13 ++++++-------
       
       3 files changed, 8 insertions(+), 7 deletions(-)
       ---
   DIR diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py
       t@@ -173,6 +173,7 @@ class ElectrumWindow(App):
        
            def on_history(self, d):
                Logger.info("on_history")
       +        self.wallet.clear_coin_price_cache()
                self._trigger_update_history()
        
            def on_fee_histogram(self, *args):
   DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
       t@@ -222,6 +222,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
                self.fetch_alias()
        
            def on_history(self, b):
       +        self.wallet.clear_coin_price_cache()
                self.new_fx_history_signal.emit()
        
            def setup_exception_hook(self):
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -182,7 +182,7 @@ class Abstract_Wallet(AddressSynchronizer):
                self.invoices = InvoiceStore(self.storage)
                self.contacts = Contacts(self.storage)
        
       -        self.coin_price_cache = {}
       +        self._coin_price_cache = {}
        
            def load_and_cleanup(self):
                self.load_keystore()
       t@@ -1178,6 +1178,9 @@ class Abstract_Wallet(AddressSynchronizer):
                        total_price += self.coin_price(ser.split(':')[0], price_func, ccy, v)
                return total_price / (input_value/Decimal(COIN))
        
       +    def clear_coin_price_cache(self):
       +        self._coin_price_cache = {}
       +
            def coin_price(self, txid, price_func, ccy, txin_value):
                """
                Acquisition price of a coin.
       t@@ -1185,17 +1188,13 @@ class Abstract_Wallet(AddressSynchronizer):
                """
                if txin_value is None:
                    return Decimal('NaN')
       -        # FIXME: this mutual recursion will be really slow and might even reach
       -        # max recursion depth if there are no FX rates available as then
       -        # nothing will be cached.
                cache_key = "{}:{}:{}".format(str(txid), str(ccy), str(txin_value))
       -        result = self.coin_price_cache.get(cache_key, None)
       +        result = self._coin_price_cache.get(cache_key, None)
                if result is not None:
                    return result
                if self.txi.get(txid, {}) != {}:
                    result = self.average_price(txid, price_func, ccy) * txin_value/Decimal(COIN)
       -            if not result.is_nan():
       -                self.coin_price_cache[cache_key] = result
       +            self._coin_price_cache[cache_key] = result
                    return result
                else:
                    fiat_value = self.get_fiat_value(txid, ccy)