Skip to content

Commit

Permalink
make owncloudsql leverage existing filecache index (#2075)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic authored Sep 16, 2021
1 parent d04e363 commit 932137b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: make owncloudsql leverage existing filecache index

When listing folders the SQL query now uses an existing index on the filecache table.

https://github.com/cs3org/reva/pull/2075
8 changes: 5 additions & 3 deletions pkg/storage/fs/owncloudsql/filecache/filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,17 @@ func (c *Cache) List(storage interface{}, p string) ([]*File, error) {
return nil, err
}

rows, err := c.db.Query(`
var rows *sql.Rows
phash := fmt.Sprintf("%x", md5.Sum([]byte(strings.Trim(p, "/"))))
rows, err = c.db.Query(`
SELECT
fc.fileid, fc.storage, fc.path, fc.parent, fc.permissions, fc.mimetype, fc.mimepart,
mt.mimetype, fc.size, fc.mtime, fc.storage_mtime, fc.encrypted, fc.unencrypted_size,
fc.name, fc.etag, fc.checksum
FROM oc_filecache fc
LEFT JOIN oc_mimetypes mt ON fc.mimetype = mt.id
WHERE path != '' AND path LIKE ? AND PATH NOT LIKE ? AND storage = ?
`, p+"%", p+"%/%", storageID)
WHERE storage = ? AND parent = (SELECT fileid FROM oc_filecache WHERE storage = ? AND path_hash=?) AND name IS NOT NULL
`, storageID, storageID, phash)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 932137b

Please sign in to comment.