-
Notifications
You must be signed in to change notification settings - Fork 543
storage/dotgit: search for incoming dir only once #935
storage/dotgit: search for incoming dir only once #935
Conversation
Search for incoming object directory was done once each time objects were accessed. This means a ReadDir of the objects path that is expensive. Now incoming directory is searched the first time an object is accessed and its name kept in DotGit to be reused. Signed-off-by: Javi Fontan <jfontan@gmail.com>
@noxora, can you check if this change is compatible with pre-commit hook? |
I do not see why this would not be compatible, it appears to be a solid change. |
I think new incoming directories can appear in subsequent calls? |
@smola, yes, that can happen if this is the use case.
While this is possible I don't think it's the common usage. Most probably go-git will be used inside the pre hook.
|
storage/filesystem/dotgit/dotgit.go
Outdated
directoryContents, err := d.fs.ReadDir(objectsPath) | ||
if err == nil { | ||
for _, file := range directoryContents { | ||
if strings.Split(file.Name(), "-")[0] == "incoming" && file.IsDir() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the same as strings.HasPrefix(file.Name(), "incoming")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
Also reformatted function comment and fixed some typos. Signed-off-by: Javi Fontan <jfontan@gmail.com>
@jfontan I thought similarly, it is possible that it could change, but if it is being used to write a hook, it shouldn't. However, if we were to treat this as volatile (which it could be, in some uncommon use cases) then this would be problematic. |
Search for incoming object directory was done once each time objects were accessed. This means a ReadDir of the objects path that is expensive. Now incoming directory is searched the first time an object is accessed and its name kept in DotGit to be reused.
This has the drawback that if the incoming object directory is created after the repo is opened it won't be found.
Related to #887