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

Code before:
            }).success(function (data) {
                $scope.remoteGUICache[address] = true;
                $scope.idToRemoteGUI[deviceId] = address;
            }).error(function (err) {
                $scope.remoteGUICache[address] = false;
                $scope.idToRemoteGUI[deviceId] = "";
            });
        }

        $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;

            if ((file.flags & (fDelete + fDirectory)) === fDelete + fDirectory) {
                return 'rmdir';
            } else if ((file.flags & fDelete) === fDelete) {
                return 'rm';
            } else if ((file.flags & fDirectory) === fDirectory) {
                return 'touch';
            } else {
                return 'sync';
            }
        }

        function parseNeeded(data) {
            $scope.needed = data;
            var merged = [];
            data.progress.forEach(function (item) {
                item.type = "progress";
                item.action = needAction(item);
                merged.push(item);
            });
            data.queued.forEach(function (item) {
                item.type = "queued";
                item.action = needAction(item);
                merged.push(item);
            });
            data.rest.forEach(function (item) {

Review comment (performance):
What's the point of `remoteGUICache`? Looks redundant to me, i.e. it always holds that if it is false, `idToRemoteGUI` is empty, and vice-versa if it's true, the other is non-empty.

Code after:
        }

        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({
                method: "OPTIONS",
                url: urlAddress,
            }).success(function (data) {
                $scope.remoteGUICache[address] = true;
                $scope.idToRemoteGUI[deviceId] = address;
            }).error(function (err) {
                $scope.remoteGUICache[address] = false;
                $scope.idToRemoteGUI[deviceId] = "";
            });
        }

        $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;

            if ((file.flags & (fDelete + fDirectory)) === fDelete + fDirectory) {
                return 'rmdir';
            } else if ((file.flags & fDelete) === fDelete) {
                return 'rm';
            } else if ((file.flags & fDirectory) === fDirectory) {