Mercurial > libervia-backend
comparison sat/core/sat_main.py @ 2767:a97c43dc4924
core: findByFeatures speed improvments:
- DeferredList are used instead of waiting for each disco individually
- a Timeout of 10 s is set for jids, to avoid waiting for minutes when some entity is unreachable (which leads to terrible user experience while waiting for a discovery page)
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Jan 2019 19:44:46 +0100 |
parents | 378188abe941 |
children | 003b8b4b56a7 |
comparison
equal
deleted
inserted
replaced
2766:93a421de0e3d | 2767:a97c43dc4924 |
---|---|
870 found_service = {} | 870 found_service = {} |
871 found_own = {} | 871 found_own = {} |
872 found_roster = {} | 872 found_roster = {} |
873 if service: | 873 if service: |
874 services_jids = yield self.findFeaturesSet(client, namespaces) | 874 services_jids = yield self.findFeaturesSet(client, namespaces) |
875 for service_jid in services_jids: | 875 services_infos = yield defer.DeferredList( |
876 infos = yield self.getDiscoInfos(client, service_jid) | 876 [self.getDiscoInfos(client, service_jid) for service_jid in services_jids] |
877 if identities is not None and not set(infos.identities.keys()).issuperset( | 877 ) |
878 identities | 878 |
879 ): | 879 for idx, (success, infos) in enumerate(services_infos): |
880 service_jid = services_jids[idx] | |
881 if not success: | |
882 log.warning( | |
883 _(u"Can't find features for service {service_jid}, ignoring") | |
884 .format(service_jid=service_jid.full())) | |
885 continue | |
886 if (identities is not None | |
887 and not set(infos.identities.keys()).issuperset(identities)): | |
880 continue | 888 continue |
881 found_identities = [ | 889 found_identities = [ |
882 (cat, type_, name or u"") | 890 (cat, type_, name or u"") |
883 for (cat, type_), name in infos.identities.iteritems() | 891 for (cat, type_), name in infos.identities.iteritems() |
884 ] | 892 ] |
887 to_find = [] | 895 to_find = [] |
888 if own_jid: | 896 if own_jid: |
889 to_find.append((found_own, [client.jid.userhostJID()])) | 897 to_find.append((found_own, [client.jid.userhostJID()])) |
890 if roster: | 898 if roster: |
891 to_find.append((found_roster, client.roster.getJids())) | 899 to_find.append((found_roster, client.roster.getJids())) |
900 | |
901 full_jids = [] | |
902 d_list = [] | |
892 | 903 |
893 for found, jids in to_find: | 904 for found, jids in to_find: |
894 for jid_ in jids: | 905 for jid_ in jids: |
895 if jid_.resource: | 906 if jid_.resource: |
896 if bare_jids: | 907 if bare_jids: |
911 resources = [client.jid.resource] | 922 resources = [client.jid.resource] |
912 for resource in resources: | 923 for resource in resources: |
913 full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource)) | 924 full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource)) |
914 if full_jid == client.jid and not local_device: | 925 if full_jid == client.jid and not local_device: |
915 continue | 926 continue |
916 infos = yield self.getDiscoInfos(client, full_jid) | 927 full_jids.append(full_jid) |
917 if infos.features.issuperset(namespaces): | 928 |
918 if identities is not None and not set( | 929 d_list.append(self.getDiscoInfos(client, full_jid)) |
919 infos.identities.keys() | 930 |
920 ).issuperset(identities): | 931 d_list = defer.DeferredList(d_list) |
921 continue | 932 # XXX: 10 seconds may be too low for slow connections (e.g. mobiles) |
922 found_identities = [ | 933 # but for discovery, that's also the time the user will wait the first time |
923 (cat, type_, name or u"") | 934 # before seing the page. |
924 for (cat, type_), name in infos.identities.iteritems() | 935 d_list.addTimeout(10, reactor) |
925 ] | 936 infos_data = yield d_list |
926 found[full_jid.full()] = found_identities | 937 |
938 for idx, (success, infos) in enumerate(infos_data): | |
939 full_jid = full_jids[idx] | |
940 if not success: | |
941 log.warning( | |
942 _(u"Can't retrieve {full_jid} infos, ignoring") | |
943 .format(full_jid=full_jid.full())) | |
944 continue | |
945 if infos.features.issuperset(namespaces): | |
946 if identities is not None and not set( | |
947 infos.identities.keys() | |
948 ).issuperset(identities): | |
949 continue | |
950 found_identities = [ | |
951 (cat, type_, name or u"") | |
952 for (cat, type_), name in infos.identities.iteritems() | |
953 ] | |
954 found[full_jid.full()] = found_identities | |
927 | 955 |
928 defer.returnValue((found_service, found_own, found_roster)) | 956 defer.returnValue((found_service, found_own, found_roster)) |
929 | 957 |
930 ## Generic HMI ## | 958 ## Generic HMI ## |
931 | 959 |