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

Code before:
                console.log("refreshConnections", data);
            }).error($scope.emitHTTPError);
        }

        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 + '/system/config').success(function (data) {
                updateLocalConfig(data);
                console.log("refreshConfig", data);
            }).error($scope.emitHTTPError);

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

        $scope.probeAddress = function (address) {
            if (address in $scope.cacheGUIAddress) {
                return $scope.cacheGUIAddress[address]
            }
            let response = $http({
                method: "OPTIONS",
                url: address,
            })
            $scope.cacheGUIAddress[address] = response.$$state.status >= 200 && response.$$state.status < 300;
            return $scope.cacheGUIAddress[address];
        }

        $scope.refreshNeed = function (page, perpage) {
            if (!$scope.neededFolder) {
                return;
            }
            var url = urlbase + "/db/need?folder=" + encodeURIComponent($scope.neededFolder);
            url += "&page=" + page;
            url += "&perpage=" + perpage;
            $http.get(url).success(function (data) {
                console.log("refreshNeed", $scope.neededFolder, data);
                parseNeeded(data);
            }).error($scope.emitHTTPError);
        }

        function needAction(file) {
            var fDelete = 4096;
            var fDirectory = 16384;


Review comment (performance):
This cache is never cleaned up, so if the ui is running for a long time a lot of stuff might accumulate here.

Perhaps it's possible to capture the content of the current cache in refreshConnectionStats,
any addresses that are still there (when it goes through data from refreshConnectionStats), it's kept there, others are remove (effectively, build a new cache, not hitting things that are in the old cache, and then replace the cache variable with the newly built cache).

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_\.\-]*\]/, ']');