Use hash path lookup vs path finding
When creating a fake symlink to a path just use hash lookup via `fetch_node` and handle that failing if the destination nodes does not exist vs. fetching the parent and linear searching for the existing target node (which gets slower as the parent node gets more children). This makes the preparing code using the little speed test helper on my not-very-fast box change to be the following: Old (preparing) - Took 29.724 seconds to run New (preparing) - Took 21.343 seconds to run Part of ongoing blueprint make-things-speedy Change-Id: I608b90ae58b4e4b6724b7f1bb8faebd118a1ec79
This commit is contained in:
		
				
					committed by
					
						
						Joshua Harlow
					
				
			
			
				
	
			
			
			
						parent
						
							f017ce854f
						
					
				
				
					commit
					24752c204b
				
			@@ -220,14 +220,13 @@ class FakeFilesystem(object):
 | 
				
			|||||||
        """Link the destionation path to the source path."""
 | 
					        """Link the destionation path to the source path."""
 | 
				
			||||||
        dest_path = self.normpath(dest_path)
 | 
					        dest_path = self.normpath(dest_path)
 | 
				
			||||||
        src_path = self.normpath(src_path)
 | 
					        src_path = self.normpath(src_path)
 | 
				
			||||||
        dirname, basename = self.split(dest_path)
 | 
					        try:
 | 
				
			||||||
        parent_node = self._fetch_node(dirname, normalized=True)
 | 
					            dest_node = self._fetch_node(dest_path, normalized=True)
 | 
				
			||||||
        child_node = parent_node.find(basename,
 | 
					        except exc.NotFound:
 | 
				
			||||||
                                      only_direct=True,
 | 
					            parent_path, basename = self.split(dest_path)
 | 
				
			||||||
                                      include_self=False)
 | 
					            parent_node = self._fetch_node(parent_path, normalized=True)
 | 
				
			||||||
        if child_node is None:
 | 
					            dest_node = self._insert_child(parent_node, basename)
 | 
				
			||||||
            child_node = self._insert_child(parent_node, basename)
 | 
					        dest_node.metadata['target'] = src_path
 | 
				
			||||||
        child_node.metadata['target'] = src_path
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __getitem__(self, path):
 | 
					    def __getitem__(self, path):
 | 
				
			||||||
        return self._get_item(self.normpath(path))
 | 
					        return self._get_item(self.normpath(path))
 | 
				
			||||||
@@ -236,11 +235,11 @@ class FakeFilesystem(object):
 | 
				
			|||||||
        path = self.normpath(path)
 | 
					        path = self.normpath(path)
 | 
				
			||||||
        value = self._copier(value)
 | 
					        value = self._copier(value)
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            item_node = self._fetch_node(path, normalized=True)
 | 
					            node = self._fetch_node(path, normalized=True)
 | 
				
			||||||
            item_node.metadata.update(value=value)
 | 
					            node.metadata.update(value=value)
 | 
				
			||||||
        except exc.NotFound:
 | 
					        except exc.NotFound:
 | 
				
			||||||
            dirname, basename = self.split(path)
 | 
					            parent_path, basename = self.split(path)
 | 
				
			||||||
            parent_node = self._fetch_node(dirname, normalized=True)
 | 
					            parent_node = self._fetch_node(parent_path, normalized=True)
 | 
				
			||||||
            self._insert_child(parent_node, basename, value=value)
 | 
					            self._insert_child(parent_node, basename, value=value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user