@@ -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,26 +1724,6 @@ 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 ) {
@@ -1753,22 +1735,56 @@ qx.Class.define("osparc.data.Resources", {
17531735 "portKey1" : portId1
17541736 } ;
17551737
1756- // eslint-disable-next-line no-underscore-dangle
1757- const cachedCPs = this . getInstance ( ) . __getCached ( "portsCompatibility" ) || { } ;
1738+ const cachedCPs = this . __getCached ( "portsCompatibility" ) || { } ;
17581739 const strUrl = JSON . stringify ( url ) ;
17591740 if ( strUrl in cachedCPs ) {
17601741 return Promise . resolve ( cachedCPs [ strUrl ] ) ;
17611742 }
1743+
1744+ // avoid request deduplication
1745+ if ( this . __portsCompatibilityPromisesCached === null ) {
1746+ this . __portsCompatibilityPromisesCached = { } ;
1747+ }
1748+ if ( strUrl in this . __portsCompatibilityPromisesCached ) {
1749+ console . log ( "returning cached promise for ports compatibility" ) ;
1750+ return this . __portsCompatibilityPromisesCached [ strUrl ] ;
1751+ }
1752+
17621753 const params = {
17631754 url
17641755 } ;
1765- return this . fetch ( "portsCompatibility" , "matchInputs" , params )
1756+ this . __portsCompatibilityPromisesCached [ strUrl ] = this . fetch ( "portsCompatibility" , "matchInputs" , params )
17661757 . then ( data => {
17671758 cachedCPs [ strUrl ] = data ;
1768- // eslint-disable-next-line no-underscore-dangle
1769- this . getInstance ( ) . __setCached ( "portsCompatibility" , cachedCPs ) ;
1759+ this . __setCached ( "portsCompatibility" , cachedCPs ) ;
17701760 return data ;
1761+ } )
1762+ . finally ( ( ) => {
1763+ // Remove the promise from the cache
1764+ delete this . __portsCompatibilityPromisesCached [ strUrl ] ;
17711765 } ) ;
1766+
1767+ return this . __portsCompatibilityPromisesCached [ strUrl ] ;
1768+ } ,
1769+ } ,
1770+
1771+ statics : {
1772+ API : "/v0" ,
1773+ fetch : function ( resource , endpoint , params , options = { } ) {
1774+ return this . getInstance ( ) . fetch ( resource , endpoint , params , options ) ;
1775+ } ,
1776+ getOne : function ( resource , params , id , useCache ) {
1777+ return this . getInstance ( ) . getOne ( resource , params , id , useCache ) ;
1778+ } ,
1779+ get : function ( resource , params , useCache , options ) {
1780+ return this . getInstance ( ) . get ( resource , params , useCache , options ) ;
1781+ } ,
1782+
1783+ getServiceUrl : function ( key , version ) {
1784+ return {
1785+ "key" : encodeURIComponent ( key ) ,
1786+ "version" : version
1787+ } ;
17721788 } ,
17731789
17741790 getErrorMsg : function ( resp ) {
0 commit comments