@@ -15,7 +15,7 @@ function getNameAfterService(url) {
1515
1616 // Find the index of "WEBSITE" or "APP" and get the next part
1717 const serviceIndex = pathParts . findIndex (
18- ( part ) => part === "WEBSITE" || part === "APP"
18+ ( part ) => part === "WEBSITE" || part === "APP" ,
1919 ) ;
2020
2121 if ( serviceIndex !== - 1 && pathParts [ serviceIndex + 1 ] ) {
@@ -50,7 +50,7 @@ function parseUrl(url) {
5050 // Extract the pathname and remove the prefix if it matches "render/APP" or "render/WEBSITE"
5151 const path = parsedUrl . pathname . replace (
5252 / ^ \/ r e n d e r \/ ( A P P | W E B S I T E ) \/ [ ^ / ] + / ,
53- ""
53+ "" ,
5454 ) ;
5555
5656 // Combine the path with remaining query params (if any)
@@ -69,7 +69,7 @@ function openNewTab(data) {
6969 requestedHandler : "UI" ,
7070 payload : data ,
7171 } ,
72- "*"
72+ "*" ,
7373 ) ;
7474}
7575// sends navigation information to the client in order to manage back/forward navigation
@@ -84,7 +84,7 @@ function sendNavigationInfoToParent(isDOMContentLoaded) {
8484 isDOMContentLoaded : isDOMContentLoaded ? true : false ,
8585 } ,
8686 } ,
87- "*"
87+ "*" ,
8888 ) ;
8989}
9090
@@ -127,6 +127,9 @@ const MAX_CONCURRENT_REQUESTS = 30;
127127let activeRequestCount = 0 ;
128128const requestQueue = [ ] ;
129129
130+ // Set to true to deduplicate identical in-flight qortalRequest calls
131+ const ENABLE_REQUEST_DEDUPLICATION = false ;
132+
130133// Debug logging (set to true to enable)
131134const DEBUG_REQUESTS = false ;
132135
@@ -246,7 +249,7 @@ function handleResponse(event, response) {
246249 data . name ,
247250 data . identifier ,
248251 data . path ,
249- false
252+ false ,
250253 ) ;
251254 }
252255 }
@@ -446,7 +449,7 @@ window.addEventListener(
446449 data . name ,
447450 data . identifier ,
448451 data . path ,
449- true
452+ true ,
450453 ) ;
451454 } ) ;
452455 } else {
@@ -455,7 +458,7 @@ window.addEventListener(
455458 data . name ,
456459 data . identifier ,
457460 data . path ,
458- true
461+ true ,
459462 ) ;
460463 }
461464 return ;
@@ -470,21 +473,21 @@ window.addEventListener(
470473 url = url . concat ( "&default=" + new Boolean ( data . default ) . toString ( ) ) ;
471474 if ( data . includeStatus != null )
472475 url = url . concat (
473- "&includestatus=" + new Boolean ( data . includeStatus ) . toString ( )
476+ "&includestatus=" + new Boolean ( data . includeStatus ) . toString ( ) ,
474477 ) ;
475478 if ( data . includeMetadata != null )
476479 url = url . concat (
477- "&includemetadata=" + new Boolean ( data . includeMetadata ) . toString ( )
480+ "&includemetadata=" + new Boolean ( data . includeMetadata ) . toString ( ) ,
478481 ) ;
479482 if ( data . nameListFilter != null )
480483 url = url . concat ( "&namefilter=" + data . nameListFilter ) ;
481484 if ( data . followedOnly != null )
482485 url = url . concat (
483- "&followedonly=" + new Boolean ( data . followedOnly ) . toString ( )
486+ "&followedonly=" + new Boolean ( data . followedOnly ) . toString ( ) ,
484487 ) ;
485488 if ( data . excludeBlocked != null )
486489 url = url . concat (
487- "&excludeblocked=" + new Boolean ( data . excludeBlocked ) . toString ( )
490+ "&excludeblocked=" + new Boolean ( data . excludeBlocked ) . toString ( ) ,
488491 ) ;
489492 if ( data . limit != null ) url = url . concat ( "&limit=" + data . limit ) ;
490493 if ( data . offset != null ) url = url . concat ( "&offset=" + data . offset ) ;
@@ -510,7 +513,7 @@ window.addEventListener(
510513 url = url . concat ( "&prefix=" + new Boolean ( data . prefix ) . toString ( ) ) ;
511514 if ( data . exactMatchNames != null )
512515 url = url . concat (
513- "&exactmatchnames=" + new Boolean ( data . exactMatchNames ) . toString ( )
516+ "&exactmatchnames=" + new Boolean ( data . exactMatchNames ) . toString ( ) ,
514517 ) ;
515518 if ( data . default != null )
516519 url = url . concat ( "&default=" + new Boolean ( data . default ) . toString ( ) ) ;
@@ -519,21 +522,21 @@ window.addEventListener(
519522 url = url . concat ( "&minlevel=" + data . minLevel ) ;
520523 if ( data . includeStatus != null )
521524 url = url . concat (
522- "&includestatus=" + new Boolean ( data . includeStatus ) . toString ( )
525+ "&includestatus=" + new Boolean ( data . includeStatus ) . toString ( ) ,
523526 ) ;
524527 if ( data . includeMetadata != null )
525528 url = url . concat (
526- "&includemetadata=" + new Boolean ( data . includeMetadata ) . toString ( )
529+ "&includemetadata=" + new Boolean ( data . includeMetadata ) . toString ( ) ,
527530 ) ;
528531 if ( data . nameListFilter != null )
529532 url = url . concat ( "&namefilter=" + data . nameListFilter ) ;
530533 if ( data . followedOnly != null )
531534 url = url . concat (
532- "&followedonly=" + new Boolean ( data . followedOnly ) . toString ( )
535+ "&followedonly=" + new Boolean ( data . followedOnly ) . toString ( ) ,
533536 ) ;
534537 if ( data . excludeBlocked != null )
535538 url = url . concat (
536- "&excludeblocked=" + new Boolean ( data . excludeBlocked ) . toString ( )
539+ "&excludeblocked=" + new Boolean ( data . excludeBlocked ) . toString ( ) ,
537540 ) ;
538541 if ( data . before != null ) url = url . concat ( "&before=" + data . before ) ;
539542 if ( data . after != null ) url = url . concat ( "&after=" + data . after ) ;
@@ -593,15 +596,16 @@ window.addEventListener(
593596 url = url . concat ( "&txGroupId=" + data . txGroupId ) ;
594597 if ( data . involving != null )
595598 data . involving . forEach (
596- ( x , i ) => ( url = url . concat ( "&involving=" + x ) )
599+ ( x , i ) => ( url = url . concat ( "&involving=" + x ) ) ,
597600 ) ;
598601 if ( data . reference != null )
599602 url = url . concat ( "&reference=" + data . reference ) ;
600603 if ( data . chatReference != null )
601604 url = url . concat ( "&chatreference=" + data . chatReference ) ;
602605 if ( data . hasChatReference != null )
603606 url = url . concat (
604- "&haschatreference=" + new Boolean ( data . hasChatReference ) . toString ( )
607+ "&haschatreference=" +
608+ new Boolean ( data . hasChatReference ) . toString ( ) ,
605609 ) ;
606610 if ( data . encoding != null )
607611 url = url . concat ( "&encoding=" + data . encoding ) ;
@@ -651,7 +655,7 @@ window.addEventListener(
651655 url = url . concat ( "?" ) ;
652656 if ( data . includeOnlineSignatures != null )
653657 url = url . concat (
654- "&includeOnlineSignatures=" + data . includeOnlineSignatures
658+ "&includeOnlineSignatures=" + data . includeOnlineSignatures ,
655659 ) ;
656660 return httpGetAsyncWithEvent ( event , url ) ;
657661
@@ -661,7 +665,7 @@ window.addEventListener(
661665 if ( data . reverse != null ) url = url . concat ( "&reverse=" + data . reverse ) ;
662666 if ( data . includeOnlineSignatures != null )
663667 url = url . concat (
664- "&includeOnlineSignatures=" + data . includeOnlineSignatures
668+ "&includeOnlineSignatures=" + data . includeOnlineSignatures ,
665669 ) ;
666670 return httpGetAsyncWithEvent ( event , url ) ;
667671
@@ -704,7 +708,7 @@ window.addEventListener(
704708 return ;
705709 }
706710 } ,
707- false
711+ false ,
708712) ;
709713
710714/**
@@ -784,8 +788,8 @@ const awaitTimeout = (timeout, reason) =>
784788 new Promise ( ( resolve , reject ) =>
785789 setTimeout (
786790 ( ) => ( reason === undefined ? resolve ( ) : reject ( reason ) ) ,
787- timeout
788- )
791+ timeout ,
792+ ) ,
789793 ) ;
790794
791795function getDefaultTimeout ( action ) {
@@ -904,7 +908,9 @@ const qortalRequestWithNoTimeout = (request, effectiveTimeoutMs) => {
904908 return new Promise ( ( res , rej ) => {
905909 const executeRequest = ( ) => {
906910 activeRequestCount ++ ;
907- executeQortalRequestImmediate ( request , effectiveTimeoutMs ) . then ( res ) . catch ( rej ) ;
911+ executeQortalRequestImmediate ( request , effectiveTimeoutMs )
912+ . then ( res )
913+ . catch ( rej ) ;
908914 } ;
909915
910916 // If under concurrent limit, execute immediately
@@ -946,12 +952,13 @@ function getRequestKey(request) {
946952 */
947953const qortalRequest = ( request ) => {
948954 // Check if identical request is already pending
949- const requestKey = getRequestKey ( request ) ;
950-
951- if ( pendingQortalRequests . has ( requestKey ) ) {
952- debugLog ( "Request deduplication hit for:" , request . action ) ;
953- // Return the existing promise instead of creating a new request
954- return pendingQortalRequests . get ( requestKey ) ;
955+ if ( ENABLE_REQUEST_DEDUPLICATION ) {
956+ const requestKey = getRequestKey ( request ) ;
957+ if ( pendingQortalRequests . has ( requestKey ) ) {
958+ debugLog ( "Request deduplication hit for:" , request . action ) ;
959+ // Return the existing promise instead of creating a new request
960+ return pendingQortalRequests . get ( requestKey ) ;
961+ }
955962 }
956963
957964 debugLog (
@@ -960,7 +967,8 @@ const qortalRequest = (request) => {
960967 "Queue size:" ,
961968 requestQueue . length ,
962969 "Active:" ,
963- activeRequestCount
970+ activeRequestCount ,
971+ request ,
964972 ) ;
965973
966974 // Create new request promise
@@ -979,11 +987,15 @@ const qortalRequest = (request) => {
979987 } )
980988 . finally ( ( ) => {
981989 // Remove from pending cache when done (success or failure)
982- pendingQortalRequests . delete ( requestKey ) ;
990+ if ( ENABLE_REQUEST_DEDUPLICATION ) {
991+ pendingQortalRequests . delete ( getRequestKey ( request ) ) ;
992+ }
983993 } ) ;
984994
985995 // Store in pending cache
986- pendingQortalRequests . set ( requestKey , requestPromise ) ;
996+ if ( ENABLE_REQUEST_DEDUPLICATION ) {
997+ pendingQortalRequests . set ( getRequestKey ( request ) , requestPromise ) ;
998+ }
987999
9881000 return requestPromise ;
9891001} ;
@@ -993,11 +1005,12 @@ const qortalRequest = (request) => {
9931005 */
9941006const qortalRequestWithTimeout = ( request , timeout ) => {
9951007 // Check if identical request is already pending
996- const requestKey = getRequestKey ( request ) ;
997-
998- if ( pendingQortalRequests . has ( requestKey ) ) {
999- // Return the existing promise instead of creating a new request
1000- return pendingQortalRequests . get ( requestKey ) ;
1008+ if ( ENABLE_REQUEST_DEDUPLICATION ) {
1009+ const requestKey = getRequestKey ( request ) ;
1010+ if ( pendingQortalRequests . has ( requestKey ) ) {
1011+ // Return the existing promise instead of creating a new request
1012+ return pendingQortalRequests . get ( requestKey ) ;
1013+ }
10011014 }
10021015
10031016 // Create new request promise
@@ -1006,11 +1019,15 @@ const qortalRequestWithTimeout = (request, timeout) => {
10061019 awaitTimeout ( timeout , "The request timed out" ) ,
10071020 ] ) . finally ( ( ) => {
10081021 // Remove from pending cache when done (success or failure)
1009- pendingQortalRequests . delete ( requestKey ) ;
1022+ if ( ENABLE_REQUEST_DEDUPLICATION ) {
1023+ pendingQortalRequests . delete ( getRequestKey ( request ) ) ;
1024+ }
10101025 } ) ;
10111026
10121027 // Store in pending cache
1013- pendingQortalRequests . set ( requestKey , requestPromise ) ;
1028+ if ( ENABLE_REQUEST_DEDUPLICATION ) {
1029+ pendingQortalRequests . set ( getRequestKey ( request ) , requestPromise ) ;
1030+ }
10141031
10151032 return requestPromise ;
10161033} ;
@@ -1027,14 +1044,17 @@ function cleanupOrphanedChannels() {
10271044 let cleanedCount = 0 ;
10281045
10291046 for ( const [ requestId , data ] of pendingMessageChannels . entries ( ) ) {
1030- const maxAge = ( data . effectiveTimeoutMs != null ? data . effectiveTimeoutMs : getDefaultTimeout ( data . request . action ) ) + CLEANUP_BUFFER_MS ;
1047+ const maxAge =
1048+ ( data . effectiveTimeoutMs != null
1049+ ? data . effectiveTimeoutMs
1050+ : getDefaultTimeout ( data . request . action ) ) + CLEANUP_BUFFER_MS ;
10311051 if ( now - data . timestamp > maxAge ) {
10321052 console . warn (
10331053 "Cleaning up orphaned MessageChannel for request:" ,
10341054 data . request . action ,
10351055 "Age:" ,
10361056 Math . round ( ( now - data . timestamp ) / 1000 ) ,
1037- "seconds"
1057+ "seconds" ,
10381058 ) ;
10391059 try {
10401060 data . channel . port1 . close ( ) ;
@@ -1060,15 +1080,15 @@ function cleanupOrphanedChannels() {
10601080 "Cleanup complete. Channels:" ,
10611081 cleanedCount ,
10621082 "Cache entries:" ,
1063- cacheCleanedCount
1083+ cacheCleanedCount ,
10641084 ) ;
10651085 debugLog (
10661086 "Stats - Pending channels:" ,
10671087 pendingMessageChannels . size ,
10681088 "Active requests:" ,
10691089 activeRequestCount ,
10701090 "Queued:" ,
1071- requestQueue . length
1091+ requestQueue . length ,
10721092 ) ;
10731093 }
10741094}
0 commit comments