Skip to content

Commit

Permalink
[api] only return files not part of a dataset when listing a users files
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Jul 24, 2024
1 parent 1247bff commit fbda0a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sda/cmd/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,5 +1193,5 @@ func (suite *TestSuite) TestListUserFiles() {
files := []database.SubmissionFileInfo{}
err = json.NewDecoder(okResponse.Body).Decode(&files)
assert.NoError(suite.T(), err, "failed to list users from DB")
assert.Equal(suite.T(), 5, len(files))
assert.Equal(suite.T(), 2, len(files))
}
11 changes: 3 additions & 8 deletions sda/internal/database/db_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,9 @@ func (dbs *SDAdb) getUserFiles(userID string) ([]*SubmissionFileInfo, error) {
db := dbs.DB

// select all files of the user, each one annotated with its latest event
const query = "SELECT f.submission_file_path, e.event, f.created_at " +
"FROM sda.files f " +
"LEFT JOIN ( " +
"SELECT DISTINCT ON (file_id) file_id, started_at, event " +
"FROM sda.file_event_log " +
"ORDER BY file_id, started_at DESC" +
") e ON f.id = e.file_id " +
"WHERE f.submission_user = $1; "
const query = "SELECT f.submission_file_path, e.event, f.created_at FROM sda.files f " +
"LEFT JOIN (SELECT DISTINCT ON (file_id) file_id, started_at, event FROM sda.file_event_log ORDER BY file_id, started_at DESC) e ON f.id = e.file_id WHERE f.submission_user = $1 " +
"AND f.id NOT IN (SELECT f.id FROM sda.files f RIGHT JOIN sda.file_dataset d ON f.id = d.file_id); "

// nolint:rowserrcheck
rows, err := db.Query(query, userID)
Expand Down

0 comments on commit fbda0a7

Please sign in to comment.