Repository: syncthing/syncthing
File: gui/default/syncthing/core/syncthingController.js (JavaScript)

Code before:
                if (!(id in $scope.idToRemoteGUI)) {
                    $scope.idToRemoteGUI[id] = "";
                }
                var port = $scope.devices[id].remoteGUIPort;
                var isNotRelayConnection = !connections[id].type.includes("relay");
                if (connections[id].address != "" && isNotRelayConnection && port > 0) {
                    var newAddress = "http://" + replaceAddressPort(connections[id].address, port);
                    if (!(newAddress in $scope.remoteGUICache)) {
                        // No cached result, trigger a new port probing asynchronously
                        $scope.probeRemoteGUIAddress(id, newAddress);
                    } else {
                        newCache[newAddress] = $scope.remoteGUICache[newAddress];
                        // Copy cached probing result in the corner case of duplicate GUI
                        // addresses for different devices.  Which is useless, but
                        // possible when behind the same NAT router.
                        if (newCache[newAddress]) {
                            $scope.idToRemoteGUI[id] = newAddress;
                        } else {
                            $scope.idToRemoteGUI[id] = "";
                        }
                    }
                }
            }
            // Replace the cache to discard stale addresses
            $scope.remoteGUICache = newCache;
            console.log("refreshRemoteGUI");
        }

        function refreshErrors() {
            $http.get(urlbase + '/system/error').success(function (data) {
                $scope.errors = data.errors;
                console.log("refreshErrors", data);
            }).error($scope.emitHTTPError);
        }

        function refreshConfig() {
            $http.get(urlbase + '/config').success(function (data) {
                updateLocalConfig(data);
                console.log("refreshConfig", data);
            }).error($scope.emitHTTPError);

            $http.get(urlbase + '/config/insync').success(function (data) {
                $scope.configInSync = data.configInSync;
            }).error($scope.emitHTTPError);
        }

        $scope.probeRemoteGUIAddress = function (deviceId, address) {
            $http({
                method: "OPTIONS",
                // Apply RFC6874 encoding for IPv6 link-local zone identifier
                url: address.replace('%', '%25'),

Review comment (performance):
That doesn't add much value? If we fear this might be very slow, then a pair of log statements like `starting refreshRemoteGUI` and here `starting refreshRemoteGUI` would give an indication in the console of how long it took.

Code after:
                var port = $scope.devices[id].remoteGUIPort;
                if (port <= 0
                    || !connections[id].address
                    || connections[id].type.includes("relay")) {
                    // Relay connections never work as desired here, nor incomplete addresses
                    $scope.idToRemoteGUI[id] = "";
                    continue;
                }
                var newAddress = "http://" + replaceAddressPort(connections[id].address, port);
                if (!(newAddress in $scope.remoteGUICache)) {
                    // No cached result, trigger a new port probing asynchronously
                    $scope.probeRemoteGUIAddress(id, newAddress);
                } else {
                    newCache[newAddress] = $scope.remoteGUICache[newAddress];
                    // Copy cached probing result in the corner case of duplicate GUI
                    // addresses for different devices.  Which is useless, but
                    // possible when behind the same NAT router.
                    if (newCache[newAddress]) {
                        $scope.idToRemoteGUI[id] = newAddress;
                    } else {
                        $scope.idToRemoteGUI[id] = "";
                    }
                }
            }
            // Replace the cache to discard stale addresses
            $scope.remoteGUICache = newCache;
        }

        function refreshErrors() {
            $http.get(urlbase + '/system/error').success(function (data) {
                $scope.errors = data.errors;
                console.log("refreshErrors", data);
            }).error($scope.emitHTTPError);
        }

        function refreshConfig() {
            $http.get(urlbase + '/config').success(function (data) {
                updateLocalConfig(data);
                console.log("refreshConfig", data);
            }).error($scope.emitHTTPError);

            $http.get(urlbase + '/config/insync').success(function (data) {
                $scope.configInSync = data.configInSync;
            }).error($scope.emitHTTPError);
        }

        $scope.probeRemoteGUIAddress = function (deviceId, address) {
            // Strip off possible IPv6 link-local zone identifier, as Angular chokes on it
            // with an (ugly, unjustified) console error message.
            var urlAddress = address.replace(/%[a-zA-Z0-9_\.\-]*\]/, ']');
            $http({