mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
use compact parameter to improve paynym search performance
This commit is contained in:
parent
c24f953e52
commit
b8979ed8b0
2 changed files with 12 additions and 4 deletions
|
@ -229,7 +229,7 @@ public class PayNymController {
|
||||||
followingList.setItems(FXCollections.observableList(new ArrayList<>()));
|
followingList.setItems(FXCollections.observableList(new ArrayList<>()));
|
||||||
findPayNym.setVisible(true);
|
findPayNym.setVisible(true);
|
||||||
|
|
||||||
AppServices.getPayNymService().getPayNym(nymIdentifier).subscribe(searchedPayNym -> {
|
AppServices.getPayNymService().getPayNym(nymIdentifier, true).subscribe(searchedPayNym -> {
|
||||||
findPayNym.setVisible(false);
|
findPayNym.setVisible(false);
|
||||||
List<PayNym> searchList = new ArrayList<>();
|
List<PayNym> searchList = new ArrayList<>();
|
||||||
searchList.add(searchedPayNym);
|
searchList.add(searchedPayNym);
|
||||||
|
|
|
@ -191,14 +191,14 @@ public class PayNymService {
|
||||||
.map(Optional::get);
|
.map(Optional::get);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<Map<String, Object>> fetchPayNym(String nymIdentifier) {
|
public Observable<Map<String, Object>> fetchPayNym(String nymIdentifier, boolean compact) {
|
||||||
Map<String, String> headers = new HashMap<>();
|
Map<String, String> headers = new HashMap<>();
|
||||||
headers.put("content-type", "application/json");
|
headers.put("content-type", "application/json");
|
||||||
|
|
||||||
HashMap<String, Object> body = new HashMap<>();
|
HashMap<String, Object> body = new HashMap<>();
|
||||||
body.put("nym", nymIdentifier);
|
body.put("nym", nymIdentifier);
|
||||||
|
|
||||||
String url = getHostUrl() + "/api/v1/nym";
|
String url = getHostUrl() + "/api/v1/nym" + (compact ? "?compact=true" : "");
|
||||||
if(log.isInfoEnabled()) {
|
if(log.isInfoEnabled()) {
|
||||||
log.info("Fetching PayNym using " + url);
|
log.info("Fetching PayNym using " + url);
|
||||||
}
|
}
|
||||||
|
@ -211,10 +211,18 @@ public class PayNymService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<PayNym> getPayNym(String nymIdentifier) {
|
public Observable<PayNym> getPayNym(String nymIdentifier) {
|
||||||
return fetchPayNym(nymIdentifier).map(nymMap -> {
|
return getPayNym(nymIdentifier, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Observable<PayNym> getPayNym(String nymIdentifier, boolean compact) {
|
||||||
|
return fetchPayNym(nymIdentifier, compact).map(nymMap -> {
|
||||||
List<Map<String, Object>> codes = (List<Map<String, Object>>)nymMap.get("codes");
|
List<Map<String, Object>> codes = (List<Map<String, Object>>)nymMap.get("codes");
|
||||||
PaymentCode code = new PaymentCode((String)codes.stream().filter(codeMap -> codeMap.get("segwit") == Boolean.FALSE).map(codeMap -> codeMap.get("code")).findFirst().orElse(codes.get(0).get("code")));
|
PaymentCode code = new PaymentCode((String)codes.stream().filter(codeMap -> codeMap.get("segwit") == Boolean.FALSE).map(codeMap -> codeMap.get("code")).findFirst().orElse(codes.get(0).get("code")));
|
||||||
|
|
||||||
|
if(compact) {
|
||||||
|
return new PayNym(code, (String)nymMap.get("nymID"), (String)nymMap.get("nymName"), (Boolean)nymMap.get("segwit"), Collections.emptyList(), Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
List<Map<String, Object>> followingMaps = (List<Map<String, Object>>)nymMap.get("following");
|
List<Map<String, Object>> followingMaps = (List<Map<String, Object>>)nymMap.get("following");
|
||||||
List<PayNym> following = followingMaps.stream().map(followingMap -> {
|
List<PayNym> following = followingMaps.stream().map(followingMap -> {
|
||||||
return PayNym.fromString((String)followingMap.get("code"), (String)followingMap.get("nymId"), (String)followingMap.get("nymName"), (Boolean)followingMap.get("segwit"), Collections.emptyList(), Collections.emptyList());
|
return PayNym.fromString((String)followingMap.get("code"), (String)followingMap.get("nymId"), (String)followingMap.get("nymName"), (Boolean)followingMap.get("segwit"), Collections.emptyList(), Collections.emptyList());
|
||||||
|
|
Loading…
Reference in a new issue