@@ -1430,6 +1430,8 @@ qx.Class.define("osparc.data.Resources", {
14301430 } ,
14311431
14321432 members : {
1433+ __portsCompatibilityPromisesCached : null ,
1434+
14331435 /**
14341436 * @param {String } resource Name of the resource as defined in the static property 'resources'.
14351437 * @param {String } endpoint Name of the endpoint. Several endpoints can be defined for each resource.
@@ -1722,56 +1724,65 @@ qx.Class.define("osparc.data.Resources", {
17221724 */
17231725 __removeCached : function ( resource , deleteId ) {
17241726 osparc . store . Store . getInstance ( ) . remove ( resource , this . self ( ) . resources [ resource ] . idField || "uuid" , deleteId ) ;
1725- }
1726- } ,
1727-
1728- statics : {
1729- API : "/v0" ,
1730- fetch : function ( resource , endpoint , params , options = { } ) {
1731- return this . getInstance ( ) . fetch ( resource , endpoint , params , options ) ;
1732- } ,
1733- getOne : function ( resource , params , id , useCache ) {
1734- return this . getInstance ( ) . getOne ( resource , params , id , useCache ) ;
1735- } ,
1736- get : function ( resource , params , useCache , options ) {
1737- return this . getInstance ( ) . get ( resource , params , useCache , options ) ;
1738- } ,
1739-
1740- getServiceUrl : function ( key , version ) {
1741- return {
1742- "key" : encodeURIComponent ( key ) ,
1743- "version" : version
1744- } ;
17451727 } ,
17461728
17471729 getCompatibleInputs : function ( node1 , portId1 , node2 ) {
1748- const url = this . __getMatchInputsUrl ( node1 , portId1 , node2 ) ;
1730+ const url = {
1731+ "serviceKey2" : encodeURIComponent ( node2 . getKey ( ) ) ,
1732+ "serviceVersion2" : node2 . getVersion ( ) ,
1733+ "serviceKey1" : encodeURIComponent ( node1 . getKey ( ) ) ,
1734+ "serviceVersion1" : node1 . getVersion ( ) ,
1735+ "portKey1" : portId1
1736+ } ;
17491737
1750- // eslint-disable-next-line no-underscore-dangle
1751- const cachedCPs = this . getInstance ( ) . __getCached ( "portsCompatibility" ) || { } ;
1738+ const cachedCPs = this . __getCached ( "portsCompatibility" ) || { } ;
17521739 const strUrl = JSON . stringify ( url ) ;
17531740 if ( strUrl in cachedCPs ) {
17541741 return Promise . resolve ( cachedCPs [ strUrl ] ) ;
17551742 }
1743+
1744+ // avoid request deduplication
1745+ if ( this . __portsCompatibilityPromisesCached === null ) {
1746+ this . __portsCompatibilityPromisesCached = { } ;
1747+ }
1748+ if ( strUrl in this . __portsCompatibilityPromisesCached ) {
1749+ return this . __portsCompatibilityPromisesCached [ strUrl ] ;
1750+ }
1751+
17561752 const params = {
17571753 url
17581754 } ;
1759- return this . fetch ( "portsCompatibility" , "matchInputs" , params )
1755+ this . __portsCompatibilityPromisesCached [ strUrl ] = this . fetch ( "portsCompatibility" , "matchInputs" , params )
17601756 . then ( data => {
17611757 cachedCPs [ strUrl ] = data ;
1762- // eslint-disable-next-line no-underscore-dangle
1763- this . getInstance ( ) . __setCached ( "portsCompatibility" , cachedCPs ) ;
1758+ this . __setCached ( "portsCompatibility" , cachedCPs ) ;
17641759 return data ;
1760+ } )
1761+ . finally ( ( ) => {
1762+ // Remove the promise from the cache
1763+ delete this . __portsCompatibilityPromisesCached [ strUrl ] ;
17651764 } ) ;
1765+
1766+ return this . __portsCompatibilityPromisesCached [ strUrl ] ;
17661767 } ,
1768+ } ,
17671769
1768- __getMatchInputsUrl : function ( node1 , portId1 , node2 ) {
1770+ statics : {
1771+ API : "/v0" ,
1772+ fetch : function ( resource , endpoint , params , options = { } ) {
1773+ return this . getInstance ( ) . fetch ( resource , endpoint , params , options ) ;
1774+ } ,
1775+ getOne : function ( resource , params , id , useCache ) {
1776+ return this . getInstance ( ) . getOne ( resource , params , id , useCache ) ;
1777+ } ,
1778+ get : function ( resource , params , useCache , options ) {
1779+ return this . getInstance ( ) . get ( resource , params , useCache , options ) ;
1780+ } ,
1781+
1782+ getServiceUrl : function ( key , version ) {
17691783 return {
1770- "serviceKey2" : encodeURIComponent ( node2 . getKey ( ) ) ,
1771- "serviceVersion2" : node2 . getVersion ( ) ,
1772- "serviceKey1" : encodeURIComponent ( node1 . getKey ( ) ) ,
1773- "serviceVersion1" : node1 . getVersion ( ) ,
1774- "portKey1" : portId1
1784+ "key" : encodeURIComponent ( key ) ,
1785+ "version" : version
17751786 } ;
17761787 } ,
17771788
0 commit comments