Skip to content

Commit

Permalink
Fix subDirs not haveing the correct age
Browse files Browse the repository at this point in the history
  • Loading branch information
rk1274 committed Oct 30, 2024
1 parent 19468ab commit 614cb47
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ replace github.com/docker/spdystream => github.com/docker/spdystream v0.1.0

// mergo moved to a vanity URL in v1.0.0
replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.16

replace github.com/wtsi-ssg/wrstat/v5 => /nfs/users/nfs_r/rk18/src/wrstat
54 changes: 33 additions & 21 deletions server/basedirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *Server) getBasedirsGroupSubdirs(c *gin.Context) {
return
}

id, basedir, ok := getSubdirsArgs(c)
id, basedir, age, ok := getSubdirsArgs(c)
if !ok {
return
}
Expand All @@ -165,41 +165,53 @@ func (s *Server) getBasedirsGroupSubdirs(c *gin.Context) {
s.getBasedirs(c, func() (any, error) {
var results []*basedirs.SubDir

for _, age := range summary.DirGUTAges {
result, err := s.basedirs.GroupSubDirs(uint32(id), basedir, age)
if err != nil {
return nil, err
}

results = append(results, result...)
// for _, age := range summary.DirGUTAges {
result, err := s.basedirs.GroupSubDirs(uint32(id), basedir, age)
if err != nil {
return nil, err
}

results = append(results, result...)
// }

return results, nil
})
}

func getSubdirsArgs(c *gin.Context) (int, string, bool) {
func getSubdirsArgs(c *gin.Context) (int, string, summary.DirGUTAge, bool) {
idStr := c.Query("id")
basedir := c.Query("basedir")
ageStr := c.Query("age")

if idStr == "" || basedir == "" {
c.AbortWithError(http.StatusBadRequest, ErrBadBasedirsQuery) //nolint:errcheck

return 0, "", false
return 0, "", summary.DGUTAgeAll, false
}

id, err := strconv.Atoi(idStr)
if err != nil {
c.AbortWithError(http.StatusBadRequest, ErrBadBasedirsQuery) //nolint:errcheck

return 0, "", false
return 0, "", summary.DGUTAgeAll, false
}

if ageStr == "" {
ageStr = "0"
}

return id, basedir, true
age, err := summary.AgeStringToDirGUTAge(ageStr)
if err != nil {
c.AbortWithError(http.StatusBadRequest, ErrBadBasedirsQuery) //nolint:errcheck

return 0, "", summary.DGUTAgeAll, false
}

return id, basedir, age, true
}

func (s *Server) getBasedirsUserSubdirs(c *gin.Context) {
id, basedir, ok := getSubdirsArgs(c)
id, basedir, age, ok := getSubdirsArgs(c)
if !ok {
return
}
Expand All @@ -213,15 +225,15 @@ func (s *Server) getBasedirsUserSubdirs(c *gin.Context) {
s.getBasedirs(c, func() (any, error) {
var results []*basedirs.SubDir

for _, age := range summary.DirGUTAges {
result, err := s.basedirs.UserSubDirs(uint32(id), basedir, age)
if err != nil {
return nil, err
}

results = append(results, result...)
// for _, age := range summary.DirGUTAges {
result, err := s.basedirs.UserSubDirs(uint32(id), basedir, age)
if err != nil {
return nil, err
}

results = append(results, result...)
// }

return results, nil
})
}
Expand All @@ -248,7 +260,7 @@ func (s *Server) isUserAuthedToReadPath(c *gin.Context, path string) bool {
}

func (s *Server) getBasedirsHistory(c *gin.Context) {
id, basedir, ok := getSubdirsArgs(c)
id, basedir, _, ok := getSubdirsArgs(c)
if !ok {
return
}
Expand Down
11 changes: 11 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,17 @@ func TestServer(t *testing.T) {
So(len(history), ShouldEqual, 1)
So(history[0].UsageInodes, ShouldEqual, 2)

response, err = query(s, EndPointBasedirSubdirUser,
fmt.Sprintf("?id=%d&basedir=%s&age=%d", usageUser[0].UID, usageUser[0].BaseDir, summary.DGUTAgeA3Y))
So(err, ShouldBeNil)
So(response.Code, ShouldEqual, http.StatusOK)
So(logWriter.String(), ShouldContainSubstring, "[GET /rest/v1/basedirs/subdirs/user")
So(logWriter.String(), ShouldContainSubstring, "STATUS=200")

subdirs, err = decodeSubdirResult(response)
So(err, ShouldBeNil)
So(len(subdirs), ShouldEqual, 17)

Convey("Which get updated by an auto-reload when the sentinal file changes", func() {
parentDir := filepath.Dir(filepath.Dir(dbPath))
sentinel := filepath.Join(parentDir, ".sentinel")
Expand Down
1 change: 1 addition & 0 deletions server/static/wrstat/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ const groupNameToIDMap = new Map<string, number>(),
<SubDirs
id={selectedID}
path={selectedDir}
age={age}
isUser={byUser}
treePath={treePath}
setTreePath={setTreePath}
Expand Down
7 changes: 4 additions & 3 deletions server/static/wrstat/src/SubDirs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import RPC from './rpc';
type SubDirParams = {
id: number;
path: string;
age: number;
isUser: boolean;
treePath: string;
justDisktree: boolean;
Expand Down Expand Up @@ -64,7 +65,7 @@ const pathJoin = (base: string, sub: string) => sub === "." ? base : base + "/"
sortNumFiles = (a: SubDir, b: SubDir) => a.NumFiles - b.NumFiles,
sortSizeFiles = (a: SubDir, b: SubDir) => a.SizeFiles - b.SizeFiles,
sortLastModifed = (a: SubDir, b: SubDir) => new Date(b.LastModified).valueOf() - new Date(a.LastModified).valueOf(),
SubdirsComponent = ({ id, path, isUser, treePath, setTreePath, justDisktree }: SubDirParams) => {
SubdirsComponent = ({ id, path, age, isUser, treePath, setTreePath, justDisktree }: SubDirParams) => {
const [subdirs, setSubdirs] = useState<SubDir[]>([]);

useEffect(() => {
Expand All @@ -74,9 +75,9 @@ const pathJoin = (base: string, sub: string) => sub === "." ? base : base + "/"
return;
}

(isUser ? RPC.getBasedirsUserSubdirs : RPC.getBasedirsGroupSubdirs)(id, path)
(isUser ? RPC.getBasedirsUserSubdirs : RPC.getBasedirsGroupSubdirs)(id, path, age)
.then(setSubdirs);
}, [id, path, isUser]);
}, [id, path, age, isUser]);

if (!subdirs || subdirs.length === 0) {
return <></>;
Expand Down

0 comments on commit 614cb47

Please sign in to comment.