flatten the nameToFile map as well

pull/62/head
Zlatin Balevsky 2021-06-05 23:39:25 +01:00
parent 71d20d075b
commit d00d6d7e18
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 18 additions and 8 deletions

View File

@ -24,7 +24,7 @@ class FileManager {
final MuWireSettings settings final MuWireSettings settings
final Map<InfoHash, SharedFile[]> rootToFiles = Collections.synchronizedMap(new HashMap<>()) final Map<InfoHash, SharedFile[]> rootToFiles = Collections.synchronizedMap(new HashMap<>())
final Map<File, SharedFile> fileToSharedFile = Collections.synchronizedMap(new HashMap<>()) final Map<File, SharedFile> fileToSharedFile = Collections.synchronizedMap(new HashMap<>())
final Map<String, Set<File>> nameToFiles = new HashMap<>() final Map<String, File[]> nameToFiles = new HashMap<>()
final Map<String, Set<File>> commentToFile = new HashMap<>() final Map<String, Set<File>> commentToFile = new HashMap<>()
final SearchIndex index final SearchIndex index
final FileTree<Void> negativeTree = new FileTree<>() final FileTree<Void> negativeTree = new FileTree<>()
@ -104,12 +104,17 @@ class FileManager {
saveNegativeTree() saveNegativeTree()
String name = sf.getFile().getName() String name = sf.getFile().getName()
Set<File> existingFiles = nameToFiles.get(name) File[] existingFiles = nameToFiles.get(name)
if (existingFiles == null) { if (existingFiles == null) {
existingFiles = new HashSet<>() existingFiles = new File[1]
nameToFiles.put(name, existingFiles) existingFiles[0] = sf.getFile()
} else {
Set<File> unique = new HashSet<>()
existingFiles.each {unique.add(it)}
unique.add(sf.getFile())
existingFiles = unique.toArray(existingFiles)
} }
existingFiles.add(sf.getFile()) nameToFiles.put(name, existingFiles)
String comment = sf.getComment() String comment = sf.getComment()
if (comment != null) { if (comment != null) {
@ -150,11 +155,16 @@ class FileManager {
} }
String name = sf.getFile().getName() String name = sf.getFile().getName()
Set<File> existingFiles = nameToFiles.get(name) File[] existingFiles = nameToFiles.get(name)
if (existingFiles != null) { if (existingFiles != null) {
existingFiles.remove(sf.file) Set<File> unique = new HashSet<>()
if (existingFiles.isEmpty()) { unique.addAll(existingFiles)
unique.remove(sf.file)
if (unique.isEmpty()) {
nameToFiles.remove(name) nameToFiles.remove(name)
} else {
existingFiles = unique.toArray(new File[0])
nameToFiles.put(name, existingFiles)
} }
} }