[sharing] fix performance issues

Fix performance issue when the user has folders with many files and want to share a new one.

https://github.com/owncloud/core/issues/10588