@@ -84,14 +84,12 @@ public enum WffJsFile {
8484
8585 public static final boolean COMPRESSED_WFF_DATA = true ;
8686
87- private static String allOptimizedContent ;
87+ private static final String allOptimizedContent ;
8888
8989 private final String filename ;
9090
9191 private final String optimizedFileContent ;
9292
93- private static volatile Map <String , Boolean > functionAndVarNames ;
94-
9593 private static String [][] minifiableParts = { { "else {" , "else{" }, { "} else" , "}else" }, { "if (" , "if(" },
9694 { ") {" , "){" } };
9795
@@ -364,7 +362,7 @@ private static final record FunctionOrVarName(String name, boolean function) {
364362
365363 // NB: passing descendingLength comparator as constructor argument
366364 // in TreeSet makes bug it also removes elements having same length
367- functionAndVarNames = new LinkedHashMap <>(functionAndVarNameList .size ());
365+ final Map < String , Boolean > functionAndVarNames = new LinkedHashMap <>(functionAndVarNameList .size ());
368366 for (final FunctionOrVarName each : functionAndVarNameList ) {
369367 functionAndVarNames .put (each .name , each .function );
370368 }
@@ -394,6 +392,9 @@ private static final record FunctionOrVarName(String name, boolean function) {
394392 functionAndVarNames .remove ("h" );
395393 functionAndVarNames .remove ("action" );
396394 functionAndVarNames .remove ("perform" );
395+ allOptimizedContent = buildAllFilesContent (functionAndVarNames );
396+ } else {
397+ allOptimizedContent = buildAllFilesContent (null );
397398 }
398399 }
399400
@@ -402,6 +403,47 @@ private WffJsFile(final String filename) {
402403 optimizedFileContent = buildOptimizedFileContent ();
403404 }
404405
406+ private static String buildAllFilesContent (final Map <String , Boolean > functionAndVarNames ) {
407+ int totalContentLength = 0 ;
408+ for (final WffJsFile wffJsFile : WffJsFile .values ()) {
409+ totalContentLength += wffJsFile .optimizedFileContent .length ();
410+ }
411+
412+ final StringBuilder builder = new StringBuilder (totalContentLength );
413+
414+ final WffJsFile [] wffJsFiles = WffJsFile .values ();
415+ for (int i = 2 ; i < wffJsFiles .length ; i ++) {
416+ builder .append ('\n' ).append (wffJsFiles [i ].optimizedFileContent );
417+ }
418+
419+ String allOptimizedContent = StringBuilderUtil .getTrimmedString (builder );
420+
421+ if (functionAndVarNames != null ) {
422+
423+ int functionId = 0 ;
424+ int variableId = 0 ;
425+
426+ for (final Entry <String , Boolean > entry : functionAndVarNames .entrySet ()) {
427+
428+ final String minName = entry .getValue () ? "f" + (++functionId ) : "v" + (++variableId );
429+ allOptimizedContent = allOptimizedContent .replace (entry .getKey (), minName );
430+ }
431+
432+ for (final String [] each : minifiableParts ) {
433+ allOptimizedContent = allOptimizedContent .replace (each [0 ], each [1 ]);
434+ }
435+
436+ if (Task .SHORT_NAME_ENABLED ) {
437+ for (final Task task : Task .getSortedTasks ()) {
438+ allOptimizedContent = allOptimizedContent .replace ("taskValues." .concat (task .name ()),
439+ "taskValues." .concat (task .getShortName ()));
440+ }
441+ }
442+ }
443+
444+ return allOptimizedContent ;
445+ }
446+
405447 private String buildOptimizedFileContent () {
406448
407449 try (final InputStream in = WffJsFile .class .getResourceAsStream (filename );
@@ -520,100 +562,23 @@ public static String getAllOptimizedContent(final String wsUrl, final String ins
520562 final int wsReconnectInterval , final boolean autoremoveParentScript , final boolean losslessCommunication ,
521563 final String onPayloadLossJS ) {
522564
523- if (allOptimizedContent != null ) {
524-
525- if (heartbeatInterval > 0 ) {
526- if (autoremoveParentScript ) {
527- return buildJsContentWithHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab ,
528- removePrevBPOnClosetTab , heartbeatInterval , wsReconnectInterval , losslessCommunication ,
529- onPayloadLossJS ).append (AUTOREMOVE_PARENT_SCRIPT ).toString ();
530- }
531- return buildJsContentWithHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
532- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS ).toString ();
533- }
534-
565+ if (heartbeatInterval > 0 ) {
535566 if (autoremoveParentScript ) {
536- return buildJsContentWithoutHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
567+ return buildJsContentWithHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
537568 heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
538569 .append (AUTOREMOVE_PARENT_SCRIPT ).toString ();
539570 }
540- return buildJsContentWithoutHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
571+ return buildJsContentWithHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
541572 heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS ).toString ();
542573 }
543574
544- try {
545-
546- int totalContentLength = 0 ;
547- for (final WffJsFile wffJsFile : WffJsFile .values ()) {
548- totalContentLength += wffJsFile .optimizedFileContent .length ();
549- }
550-
551- final StringBuilder builder = new StringBuilder (totalContentLength );
552-
553- final WffJsFile [] wffJsFiles = WffJsFile .values ();
554- for (int i = 2 ; i < wffJsFiles .length ; i ++) {
555- builder .append ('\n' ).append (wffJsFiles [i ].optimizedFileContent );
556- }
557-
558- allOptimizedContent = StringBuilderUtil .getTrimmedString (builder );
559-
560- if (PRODUCTION_MODE && functionAndVarNames != null ) {
561-
562- synchronized (WffJsFile .class ) {
563-
564- if (functionAndVarNames != null ) {
565-
566- int functionId = 0 ;
567- int variableId = 0 ;
568-
569- for (final Entry <String , Boolean > entry : functionAndVarNames .entrySet ()) {
570-
571- final String minName = entry .getValue () ? "f" + (++functionId ) : "v" + (++variableId );
572- allOptimizedContent = allOptimizedContent .replace (entry .getKey (), minName );
573- }
574-
575- for (final String [] each : minifiableParts ) {
576- allOptimizedContent = allOptimizedContent .replace (each [0 ], each [1 ]);
577- }
578-
579- // there is bug while enabling this, also enable in Task
580- // for (final Task task : Task.getSortedTasks()) {
581- // allOptimizedContent = allOptimizedContent
582- // .replace(task.name(), task.getShortName());
583- // }
584-
585- functionAndVarNames = null ;
586- minifiableParts = null ;
587-
588- }
589-
590- }
591-
592- }
593-
594- if (heartbeatInterval > 0 ) {
595- if (autoremoveParentScript ) {
596- return buildJsContentWithHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab ,
597- removePrevBPOnClosetTab , heartbeatInterval , wsReconnectInterval , losslessCommunication ,
598- onPayloadLossJS ).append (AUTOREMOVE_PARENT_SCRIPT ).toString ();
599- }
600- return buildJsContentWithHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
601- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS ).toString ();
602- }
603-
604- if (autoremoveParentScript ) {
605- return buildJsContentWithoutHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
606- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
607- .append (AUTOREMOVE_PARENT_SCRIPT ).toString ();
608- }
575+ if (autoremoveParentScript ) {
609576 return buildJsContentWithoutHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
610- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS ).toString ();
611- } catch (final Exception e ) {
612- if (LOGGER .isLoggable (Level .SEVERE )) {
613- LOGGER .log (Level .SEVERE , e .getMessage (), e );
614- }
577+ heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
578+ .append (AUTOREMOVE_PARENT_SCRIPT ).toString ();
615579 }
616- return "" ;
580+ return buildJsContentWithoutHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
581+ heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS ).toString ();
617582 }
618583
619584 private static StringBuilder buildJsContentWithHeartbeat (final String wsUrl , final String instanceId ,
0 commit comments