Skip to content

Commit efdbe68

Browse files
authored
Add shared_docs param (#4548)
A `shared_docs` param is added to the GET `/sharings/doctype` route, in order for the client to tell whether or not the `shared_docs` relationships is required in the response, as this can be costful in case of sharings with a lot of documents.
2 parents a98e384 + 642a4a7 commit efdbe68

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

docs/sharing.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,15 @@ Content-Type: application/vnd.api+json
433433
Get information about all the sharings that have a rule for the given doctype.
434434
This includes the content of the rules, the members, as well as the already
435435
shared documents for this sharing.
436+
A `shared_docs` query parameter is supported to control whether or not the
437+
shared docs should be included in the response. Default is true.
438+
This can be costful in case of large sharings, so it can be a good idea to set
439+
it to false for performances.
436440

437441
#### Request
438442

439443
```http
440-
GET /sharings/doctype/io.cozy.files HTTP/1.1
444+
GET /sharings/doctype/io.cozy.files?shared_docs=true HTTP/1.1
441445
Host: alice.example.net
442446
Accept: application/vnd.api+json
443447
```

web/sharings/sharings.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ func CountNewShortcuts(c echo.Context) error {
198198
func GetSharingsInfoByDocType(c echo.Context) error {
199199
inst := middlewares.GetInstance(c)
200200
docType := c.Param("doctype")
201-
201+
withSharedDocs, err := strconv.ParseBool(c.QueryParam("shared_docs"))
202+
if err != nil {
203+
withSharedDocs = true
204+
}
202205
sharings, err := sharing.GetSharingsByDocType(inst, docType)
203206
if err != nil {
204207
inst.Logger().WithNamespace("sharing").Errorf("GetSharingsByDocType error: %s", err)
@@ -214,10 +217,14 @@ func GetSharingsInfoByDocType(c echo.Context) error {
214217
for sID := range sharings {
215218
sharingIDs = append(sharingIDs, sID)
216219
}
217-
sDocs, err := sharing.GetSharedDocsBySharingIDs(inst, sharingIDs)
218-
if err != nil {
219-
inst.Logger().WithNamespace("sharing").Errorf("GetSharedDocsBySharingIDs error: %s", err)
220-
return wrapErrors(err)
220+
221+
var sDocs map[string][]couchdb.DocReference
222+
if withSharedDocs {
223+
sDocs, err = sharing.GetSharedDocsBySharingIDs(inst, sharingIDs)
224+
if err != nil {
225+
inst.Logger().WithNamespace("sharing").Errorf("GetSharedDocsBySharingIDs error: %s", err)
226+
return wrapErrors(err)
227+
}
221228
}
222229

223230
res := make([]*sharing.APISharing, 0, len(sharings))

0 commit comments

Comments
 (0)