[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
Please add a comment to explain this better