From 437c804432814e92b046d9165f723a0357451bc3 Mon Sep 17 00:00:00 2001 From: j2blake Date: Tue, 8 Nov 2011 21:59:57 +0000 Subject: [PATCH] NIHVIVO-2343 Use a simpler query for the profile auto-complete to try to speed the response. Is it enough? --- .../web/js/account/accountProxyItemsPanel.js | 61 +++++++++++++++---- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/webapp/web/js/account/accountProxyItemsPanel.js b/webapp/web/js/account/accountProxyItemsPanel.js index 08bc65e8b..5d81a23a6 100644 --- a/webapp/web/js/account/accountProxyItemsPanel.js +++ b/webapp/web/js/account/accountProxyItemsPanel.js @@ -127,29 +127,36 @@ function statusFieldUpdater(element, minLength) { } var profileQuery = "" - + "PREFIX fn: \n" + "PREFIX rdf: \n" + "PREFIX rdfs: \n" - + "PREFIX foaf: \n" - + "PREFIX vitro: \n" - + "PREFIX vpublic: \n" - + "PREFIX auth: \n" + "\n" + "SELECT DISTINCT ?uri ?label ?classLabel ?imageUrl \n" + "WHERE { \n" + " %typesUnion% \n" + " ?uri rdfs:label ?label ; \n" + + " FILTER (REGEX(str(?label), '^%term%', 'i')) \n" + + "} \n" + + "ORDER BY ASC(?label) \n" + + "LIMIT 25 \n"; + +var profileMoreInfoQuery = "" + + "PREFIX rdf: \n" + + "PREFIX rdfs: \n" + + "PREFIX vitro: \n" + + "PREFIX vpublic: \n" + + "\n" + + "SELECT DISTINCT ?classLabel ?imageUrl \n" + + "WHERE { \n" + " OPTIONAL { \n" - + " ?uri vitro:mostSpecificType ?type. \n" + + " <%uri%> vitro:mostSpecificType ?type. \n" + " ?type rdfs:label ?classLabel \n" + " } \n" + " OPTIONAL { \n" - + " ?uri vpublic:mainImage ?imageUri. \n" + + " <%uri%> vpublic:mainImage ?imageUri. \n" + " ?imageUri vpublic:thumbnailImage ?thumbUri. \n" + " ?thumbUri vpublic:downloadLocation ?thumbstreamUri. \n" + " ?thumbstreamUri vpublic:directDownloadUrl ?imageUrl. \n" + " } \n" - + " FILTER (REGEX(str(?label), '^%term%', 'i')) \n" + "} \n" + "ORDER BY ASC(?label) \n" + "LIMIT 25 \n"; @@ -170,7 +177,7 @@ var proxyQuery = "" + "ORDER BY ASC(?lastName) ASC(?firstName) \n" + "LIMIT 25 \n"; -var moreInfoQuery = "" +var proxyMoreInfoQuery = "" + "PREFIX rdfs: \n" + "PREFIX vitro: \n" + "PREFIX p.1: \n" @@ -202,8 +209,8 @@ var getAdditionalProxyInfo = function(parent, info, externalAuthId) { url: proxyContextInfo.sparqlQueryUrl, dataType: 'json', data: { - query: moreInfoQuery.replace("%matchingProperty%", proxyContextInfo.matchingProperty) - .replace("%externalAuthId%", externalAuthId) + query: proxyMoreInfoQuery.replace(/%matchingProperty%/g, proxyContextInfo.matchingProperty) + .replace(/%externalAuthId%/g, externalAuthId) }, complete: function(xhr, status) { var results = $.parseJSON(xhr.responseText); @@ -236,7 +243,33 @@ var applyProfileTypes = function(rawQuery) { typeClause += ' .'; } } - return rawQuery.replace("%typesUnion%", typeClause); + return rawQuery.replace(/%typesUnion%/g, typeClause); +} + +/* + * This function will allow a profile panel to execute another query for each profile. + */ +var getAdditionalProfileInfo = function(parent, info) { + $.ajax({ + url: proxyContextInfo.sparqlQueryUrl, + dataType: 'json', + data: { + query: profileMoreInfoQuery.replace(/%uri%/g, info.uri) + }, + complete: function(xhr, status) { + var results = $.parseJSON(xhr.responseText); + var parsed = sparqlUtils.parseSparqlResults(results); + if (parsed.length > 0) { + if ("classLabel" in parsed[0]) { + info.classLabel = parsed[0].classLabel; + } + if ("imageUrl" in parsed[0]) { + info.imageUrl = proxyContextInfo.baseUrl + parsed[0].imageUrl; + } + parent.displayItemData(); + } + } + }); } /* @@ -277,7 +310,9 @@ $(document).ready(function() { query: query, model: '' } - this["proxyItemsPanel"] = new proxyItemsPanel(this, context); + var pip = new proxyItemsPanel(this, context); + pip.getAdditionalData = getAdditionalProfileInfo; + this["proxyItemsPanel"] = pip; }); /*