Skip to content
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

enh: Show remote shares in external section #51312

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nfebe
Copy link
Contributor

@nfebe nfebe commented Mar 6, 2025

Description

  • feat(files_sharing): Add types filter to getShares

    Improve the OCS files sharing API to include a share type filter in getShares

  • feat(sharing_tab): Show remote shares in external shares section

Screenshots

Before After
before after

Resolves : #51226

nfebe added 2 commits March 7, 2025 12:05
Improve the OCS files sharing API to include a share type filter in `getShares`

Signed-off-by: nfebe <[email protected]>
@nfebe nfebe marked this pull request as ready for review March 7, 2025 11:12
@nfebe nfebe requested review from a team as code owners March 7, 2025 11:12
Copy link
Contributor

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need two requests to the backend, we also can just filter on the frontend

Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the filtering should be done on the frontend.
Also this breaks other API users because you introduce a new field without a default value that is the same as the current behavior.

@nfebe
Copy link
Contributor Author

nfebe commented Mar 7, 2025

Not sure we need two requests to the backend, we also can just filter on the frontend

I think having this in the API is necessary. An API that returns different types of shares should naturally support filtering by type. Beyond this specific use case, I’m actually surprised that this wasn’t already possible in the GET. It seems like a basic and useful capability.

cc: @susnux

Agreed, the filtering should be done on the frontend.
Also this breaks other API users because you introduce a new field without a default value that is the same as the current behavior.

That is not true. This change is not a breaking change. Omitting the parameter results in the current behavior, returning all shares as expected. Internal and external apps will continue to function as before.

cc: @provokateurin


Generally, this increases performance, especially for instances/users with a sizable number of shares, Splitting and parallelizing the request has clear benefits and some drawbacks and so does frontend filtering.

The new new API option/field, is a valuable addition because asides giving the client more flexibility it does not change current behavior, as long as it gets into the OpenAPI spec/admin docs I believe this has more advantages than drawbacks.

@susnux
Copy link
Contributor

susnux commented Mar 7, 2025

Generally, this increases performance, especially for instances/users with a sizable number of shares, Splitting and parallelizing the request has clear benefits and some drawbacks and so does frontend filtering.

I am not sure here.

  1. the sidebar loading will increase as the second request itself will add a delay (network)
  2. You need to setup the whole enviroment (filesystem / shares) two times as we never ask for only one of both, so this basically duplicates the request time. Meaning if in worst case there is no other php process available this now will take twice the time as before and even if handled sequentially it will double the server load.

So I do not see any benefit here as the shares are requested the same way, there is no shortcut taken while fetching the shares, only formatting them is skipped. But this means now we have two fetch all shares 2 times iterate overthem and filter them.

With the types filter in place (1e7f53e) we should avoid,
fetching all shares.

Preventing potential N+1s

Signed-off-by: nfebe <[email protected]>
@nfebe nfebe force-pushed the fix/51226/show-remote-shares-as-external branch from 6339447 to cca22cb Compare March 7, 2025 16:20
@nfebe
Copy link
Contributor Author

nfebe commented Mar 7, 2025

the sidebar loading will increase as the second request itself will add a delay (network)

If making two requests results to smaller response sizes then, it is generally faster. The different components can render as the data is available.

You need to setup the whole enviroment (filesystem / shares) two times as we never ask for only one of both, so this basically duplicates the request time. Meaning if in worst case there is no other php process available this now will take twice the time as before and even if handled sequentially it will double the server load.

This is a legitimate concern, I have added a commit to avoid fetching ALL shares, as the method that does it sequentially iterates over all the providers, if we simply pass the types (providers) to this method, then it stops most of this problem.

foreach ($providers as $provider) {
if (!$this->shareManager->shareProviderExists($provider)) {
continue;
}
$providerShares =
$this->shareManager->getSharesBy($viewer, $provider, $node, $reShares, -1, 0);
$shares = array_merge($shares, $providerShares);
}

The issue of more requests -> more server load remains nonetheless this kind of filtering is usually handled at the backend and even we do not want to use it here, I still think it is essential that shares can be filtered by type.

cc: @susnux

Copy link
Contributor Author

@nfebe nfebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am aware of the missing openapi update, had some issues with composer exec generate-spec.

While the main reviews are being cleared that would be handled.

@provokateurin
Copy link
Member

I'm mostly siding with @susnux here and my previous comments were under the assumption that the providers were told which share types to query (because I didn't look at the code further).
If we really want to make some performance improvements, then the providers need to be optimized to only query the expected types.
TBH the entire system is a bit weird with fetching all shares from all provider types all the time, but at least it is consistent. We can't just randomly change this, with minimal performance reward, and possible break API consumers.

Comment on lines +944 to +961
$types = array_map('intval', $types);
foreach ($types as $type) {
match ($type) {
IShare::TYPE_USER,
IShare::TYPE_GROUP,
IShare::TYPE_LINK,
IShare::TYPE_EMAIL,
IShare::TYPE_REMOTE,
IShare::TYPE_REMOTE_GROUP,
IShare::TYPE_CIRCLE,
IShare::TYPE_ROOM,
IShare::TYPE_DECK,
IShare::TYPE_SCIENCEMESH => null,
default => throw new OCSBadRequestException(
$this->l->t('Cannot filter by unknown share types')
),
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do array_filter instead and check if the result is not empty. If the match just returns true/false it's good, but using it like this is not a great idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗️ In progress
Development

Successfully merging this pull request may close these issues.

[Bug]: Remote shares are shown as internal shares
3 participants