more efficient mass unsharing

pull/62/head
Zlatin Balevsky 2021-06-12 10:56:01 +01:00
parent d7423e7e08
commit 300404915d
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 41 additions and 43 deletions

View File

@ -540,60 +540,58 @@ class MainFrameModel {
runInsideUIAsync {
synchronized (allSharedFiles) {
allSharedFiles.removeAll(e.unsharedFiles)
shared.retainAll(allSharedFiles)
}
loadedFiles = allSharedFiles.size()
for (SharedFile sharedFile : e.unsharedFiles) {
boolean wasVisible = shared.remove(sharedFile)
DefaultMutableTreeNode dmtn = fileToNode.remove(sharedFile)
if (dmtn != null) {
if (dmtn == null)
continue
if (wasVisible) {
Object[] path = dmtn.getUserObjectPath()
DefaultMutableTreeNode otherNode = treeRoot
for (int i = 1; i < path.length; i++) {
Object o = path[i]
DefaultMutableTreeNode next = null
for (int j = 0; j < otherNode.childCount; j++) {
if (otherNode.getChildAt(j).getUserObject() == o) {
next = otherNode.getChildAt(j)
break
}
}
if (next == null)
throw new IllegalStateException()
otherNode = next
}
while (true) {
def parent = otherNode.getParent()
otherNode.removeFromParent()
if (parent.getChildCount() == 0) {
otherNode = parent
} else
break
}
}
List<File> unshared = new ArrayList<>()
while (true) {
def parent = dmtn.getParent()
parent.remove(dmtn)
if (parent == allFilesTreeRoot)
Object[] path = dmtn.getUserObjectPath()
DefaultMutableTreeNode otherNode = treeRoot
for (int i = 1; i < path.length; i++) {
Object o = path[i]
DefaultMutableTreeNode next = null
for (int j = 0; j < otherNode.childCount; j++) {
if (otherNode.getChildAt(j).getUserObject() == o) {
next = otherNode.getChildAt(j)
break
if (parent.getChildCount() == 0) {
File file = parent.getUserObject().file
if (core.watchedDirectoryManager.isWatched(file))
unshared.add(file)
dmtn = parent
continue
}
}
if (next == null)
throw new IllegalStateException()
otherNode = next
}
while (true) {
def parent = otherNode.getParent()
otherNode.removeFromParent()
if (parent.getChildCount() == 0) {
otherNode = parent
} else
break
}
List<File> unshared = new ArrayList<>()
while (true) {
def parent = dmtn.getParent()
parent.remove(dmtn)
if (parent == allFilesTreeRoot)
break
if (parent.getChildCount() == 0) {
File file = parent.getUserObject().file
if (core.watchedDirectoryManager.isWatched(file))
unshared.add(file)
dmtn = parent
continue
}
if (!unshared.isEmpty()) {
File unsharedRoot = unshared.get(unshared.size() - 1)
core.eventBus.publish(new DirectoryUnsharedEvent(directory: unsharedRoot))
}
break
}
if (!unshared.isEmpty()) {
File unsharedRoot = unshared.get(unshared.size() - 1)
core.eventBus.publish(new DirectoryUnsharedEvent(directory: unsharedRoot))
}
}