URI: 
       tremove expensive sql request, python set comparison is faster - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 115113f492f3a84187bd267269edc497b47897db
   DIR parent af7d7e883c760caedbe8ba738e450fae535b1886
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Mon, 17 Jun 2019 09:30:14 +0200
       
       remove expensive sql request, python set comparison is faster
       
       Diffstat:
         M electrum/lnrouter.py                |      17 ++++-------------
         M electrum/lnworker.py                |       2 +-
       
       2 files changed, 5 insertions(+), 14 deletions(-)
       ---
   DIR diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py
       t@@ -41,7 +41,7 @@ from sqlalchemy.orm.query import Query
        from sqlalchemy.ext.declarative import declarative_base
        from sqlalchemy.sql import not_, or_
        
       -from .sql_db import SqlDB, sql, SQLITE_LIMIT_VARIABLE_NUMBER
       +from .sql_db import SqlDB, sql
        from . import constants
        from .util import bh2u, profiler, get_headers_dir, bfh, is_ip_address, list_enabled_bits, print_msg, chunks
        from .logging import Logger
       t@@ -228,18 +228,9 @@ class ChannelDB(SqlDB):
                self.num_nodes = self.DBSession.query(NodeInfo).count()
        
            @sql
       -    @profiler
       -    def compare_channels(self, channel_ids):
       -        ids = [x.hex() for x in channel_ids]
       -        known = set()
       -        # I need to get the unknown, and also the channels that need refresh
       -        for ids_chunk in chunks(ids, SQLITE_LIMIT_VARIABLE_NUMBER):
       -            known_part = self.DBSession \
       -                     .query(ChannelInfo) \
       -                     .filter(ChannelInfo.short_channel_id.in_(ids_chunk)) \
       -                     .all()
       -            known |= set(bfh(r.short_channel_id) for r in known_part)
       -        return known
       +    def known_ids(self):
       +        known = self.DBSession.query(ChannelInfo.short_channel_id).all()
       +        return set(bfh(r.short_channel_id) for r in known)
        
            @sql
            def add_recent_peer(self, peer: LNPeerAddr):
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -274,7 +274,7 @@ class LNGossip(LNWorker):
                    await asyncio.sleep(5)
        
            def add_new_ids(self, ids):
       -        known = self.channel_db.compare_channels(ids)
       +        known = self.channel_db.known_ids()
                new = set(ids) - set(known)
                self.unknown_ids.update(new)