-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug when renaming multiple objects #1607
Draft
peterjan
wants to merge
13
commits into
api-breakers
Choose a base branch
from
pj/directories-2
base: api-breakers
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+489
−121
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
463adf8
stores: fix MakeDirsForPath
peterjan c542e63
stores: add InsertDirectoriesForRename
peterjan 29b5a00
stores: implement InsertDirectoriesForRename
peterjan f2847b7
stores: add migration 00024_fix_directories
peterjan e53e29a
stores: extend TestRenameObjects
peterjan 64a2e70
testing: fix TestObjectsWithDelimiterSlash
peterjan bdb28c2
stores: fix MySQL query
peterjan 45d3f84
stores: fix NDF in TestRenameObjects
peterjan 3f86a0b
stores: make sure both impl. of InsertDirectoriesForRename are identical
peterjan 4f0297c
stores: treat explicit dirs as objects
peterjan 4b91def
object: add TestDirectories and cleanup PR
peterjan d290f70
lint: remove trailing newline
peterjan 58b8c46
sql: fix sprintf
peterjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package object | ||
|
||
import "strings" | ||
|
||
// Directories returns the directories for the given path. When explicit is | ||
// true, the returned directories do not include the path itself should it be a | ||
// directory. The root path ('/') is always excluded. | ||
func Directories(path string, explicit bool) (dirs []string) { | ||
if explicit { | ||
path = strings.TrimSuffix(path, "/") | ||
} | ||
if path == "/" { | ||
return nil | ||
} | ||
for i, r := range path { | ||
if r != '/' { | ||
continue | ||
} | ||
dir := path[:i+1] | ||
if dir == "/" { | ||
continue | ||
} | ||
dirs = append(dirs, dir) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package object | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestDirectories(t *testing.T) { | ||
cases := []struct { | ||
path string | ||
explicit bool | ||
dirs []string | ||
}{ | ||
{"/", true, nil}, | ||
{"/", false, nil}, | ||
{"/foo", true, nil}, | ||
{"/foo", false, nil}, | ||
{"/foo/bar", true, []string{"/foo/"}}, | ||
{"/foo/bar", false, []string{"/foo/"}}, | ||
{"/foo/bar/", true, []string{"/foo/"}}, | ||
{"/foo/bar/", false, []string{"/foo/", "/foo/bar/"}}, | ||
} | ||
for _, c := range cases { | ||
if got := Directories(c.path, c.explicit); !reflect.DeepEqual(got, c.dirs) { | ||
t.Fatalf("unexpected dirs for path %v (explicit %t), %v != %v", c.path, c.explicit, got, c.dirs) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@ChrisSchinnerl I'm not a big fan of the naming here, I went with
explicit
because we have this test calledTestObjectsExplicitDir
re-reading it now makes me think I have to inverse it actually. Holding off on that for now until we review the entire thing.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.
Tbh I'm not a fan of having the bool. It feels a bit too forced. The way I understand it is that it's only required for
InsertDirectoriesForRename
. Looking at that method it seems very verbose. I'm pretty sure your first instinct was to just update the directory names instead of doing the whole mapping thing but you ran into issues due to the fact that thedirectories
table doesn't contain the bucket.I think it might be worth adding the bucket id to the directories table and extending the unique key to cover that.
Then simplify
InsertDirectoriesForRename
and finally get rid of theexplicit
bool since we should be able to just update all directories of the bucket that we rename within. My guess is that that's also a lot faster than looping and inserting directories.That makes the migration more complicated but if we ever decide to use the
directories
table as a cache for fields likesize
andhealth
of contained objects, we will need to introduce buckets to that table anyway.