Skip to content

introduce callForSeenUsers and countSeenUsers#26361

Merged
DeepDiver1975 merged 4 commits into
masterfrom
callforusersthatloggedin
Oct 19, 2016
Merged

introduce callForSeenUsers and countSeenUsers#26361
DeepDiver1975 merged 4 commits into
masterfrom
callforusersthatloggedin

Conversation

@butonic

@butonic butonic commented Oct 12, 2016

Copy link
Copy Markdown
Contributor

I was running into the upgrade trying to iterate over 170000 zombie users in my two test ldap servers, when only 6 of them ever logged in. Instead of waiting 5-6 hours or maybe even longer I decided to take the time and find a better solution.

This pr introduces callForSeenUsers() and countSeenUsers() to allow only executing a callback for users that logged in at least once and as a result have a home directory that has been initialized. It also helps prevent out of memory errors.

cc @PVince81 @DeepDiver1975 there are at least two further occurences (SyncService and SyncBirthdayCalendar) of callForAllUsers in the dav app, but they seem to be related to calendar and contacts. We might add other callFor???User methods.

Backport to 9 strongly requested ❗ ❕ !!!111einself

@butonic butonic added this to the 9.2 milestone Oct 12, 2016
@mention-bot

Copy link
Copy Markdown

@butonic, thanks for your PR! By analyzing the history of the files in this pull request, we identified @PVince81, @rullzer and @DeepDiver1975 to be potential reviewers.

@butonic butonic force-pushed the callforusersthatloggedin branch 2 times, most recently from 438a6f5 to e388086 Compare October 13, 2016 08:59

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

won't work here because even users who haven't logged in might have broken "files_target" and duplicate shares due to the fact that some sharing API calls would set up their FS...

Comment thread lib/private/User/Manager.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please add a unit test for this. It will further confirm that it works with all DBs.

@PVince81

Copy link
Copy Markdown
Contributor

Good idea !

Comment thread lib/public/IUserManager.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

interface change, can't backport directly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would it be easier to simply add a flag $onlySeen = false to callForAllUsers to avoid changing the interface ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hm, that still changes the return type of countUsers() to int if $onlySeen is true. I left the new methods in the interface ... should I remove them from IUserManager completely? I dislike munching everything into a single call. We can backport it that way, but in the future I want a clean API.

The callForSeenUsers call eg, does not support searching for users because we only have the userid in the preferences. callForAllUsers iterates over the user backends and the LDAP backend may search displayname or emaul in addition to the userid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So what to do with the interface breakage ?

In the backport you'd remove the methods from the interface ? Ok.
But then we also need to add checks everywhere if (is_callable($userManager, 'callForSeenUsers')) then call it, else fallback to the old way.

I'm fine adding these methods in 9.2.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually adding methods in 9.2 would also require a new interface IUserManager2 that extends IUserManager.

Unless we assume that no one ever bothered to implement their own user manager... there is currently no config for easy overriding without hacking server.php ...

@DeepDiver1975 thoughts ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Somewhere (maybe in another comment), @DeepDiver1975 answered that it is currently not possible anyway to override the interface, so changing it is ok in 9.2

@butonic butonic force-pushed the callforusersthatloggedin branch from e388086 to 8f38ca8 Compare October 13, 2016 19:31
@DeepDiver1975

Copy link
Copy Markdown
Member

I was thinking about this : With the user account table I want the call for uses to iterate only over known users.
Accessing not yet logged in users is a matter of search only from my pov.

@butonic butonic force-pushed the callforusersthatloggedin branch 3 times, most recently from ac6b18b to d57f314 Compare October 14, 2016 12:32
@butonic

butonic commented Oct 17, 2016

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 What is the status af the user account table?

For this PR the tests are passing and it is a clear improvement. @PVince81 @DeepDiver1975 can we merge so I can backport to 9.0.?

Comment thread lib/private/User/Manager.php Outdated
* @since 9.2.0
*/
public function countSeenUsers() {
$limit = 10000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hard-coded limit ? should we have this as argument ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you pass that as an argument, you will have different hard-coded values for each use. Making it harder to test. If this should be variable, we should inject it as a configuration value with propel, but i think it shouldn't.

* @since 9.0.0
*/
public function callForSeenUsers (\Closure $callback) {
$limit = 1000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hardcoded limit ? pass as argument ?

Also, in the count method you hard-coded to 10000 while here only 1000. Any reason ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

gut feeling. count only iterates. call executes a callback ... who knows what is done in there and how much memory is leaked

@butonic

butonic commented Oct 18, 2016

Copy link
Copy Markdown
Contributor Author

@PhilippSchaffrath could you review, pls?

Comment thread lib/private/User/Manager.php Outdated
* if $onlySeen is true only an int is returned
*/
public function countUsers() {
public function countUsers($onlySeen = false) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The domain is a little inconsistent here, i would like $onlySeen to be called something like $hasLoggedIn.

public function countUsers() {
public function countUsers($onlySeen = false) {
if ($onlySeen) {
return $this->countSeenUsers();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

countHasLoggedInUsers()? looks ugly but clarifies, hm k.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/owncloud/windows_network_drive/pull/51 has already been merged we can change the name after getting this in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't want to block this, it's just a reminder to keep an easy and consistent domain so it's more easy to understand the code.

continue;
public function callForAllUsers(\Closure $callback, $search = '', $onlySeen = false) {
if ($onlySeen) {
$this->callForSeenUsers($callback);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would like to see a separation here. callForAllUsers should always call a callback for all users, not sometimes if parameter x is set to y only a subset of all users. Since callForSeenUsers already exists, why does it need to be cascaded in here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@PVince81 and @DeepDiver1975 wanted a param to make backporting easier since we don't backport API changes ...

$user4->delete();
}

public function testCallForSeenUsers() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

smart test, like it 👍

@DeepDiver1975 DeepDiver1975 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually adding methods in 9.2 would also require a new interface IUserManager2 that extends IUserManager.

This is only necessary for interfaces where we allow/expect alternative implementations out there.
I see no reason why an alternative implementation would make sense - furthermore there is no way to register one.

Comment thread lib/private/User/Manager.php Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

9.2.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@butonic seems you missed this one

Comment thread lib/private/User/Manager.php Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

inject

@butonic butonic force-pushed the callforusersthatloggedin branch from d57f314 to 8513f2a Compare October 18, 2016 13:51
@butonic

butonic commented Oct 18, 2016

Copy link
Copy Markdown
Contributor Author

I addressed most issues and also removed the sql hack for oracle because it was unnecessary to order the results in fhe first place.

@DeepDiver1975 @PVince81 @PhilippSchaffrath please review

@PVince81

Copy link
Copy Markdown
Contributor

Looks good to me, also tested with 200 LDAP users where only 4 logged in and saw that only 4 got processed for the avatar move.

@butonic please adjust the "since" tag from above and this is good from my POV 👍

@butonic

butonic commented Oct 18, 2016

Copy link
Copy Markdown
Contributor Author

@PVince81 done

@DeepDiver1975

Copy link
Copy Markdown
Member

👍

@PVince81

PVince81 commented Dec 7, 2016

Copy link
Copy Markdown
Contributor

stable9.1: #27248
stable9: #26415

jvillafanez pushed a commit that referenced this pull request Feb 24, 2017
* introduce callForSeenUsers and countSeenUsers

* add tests

* oracle should support not null on clob

* since 9.2.0

Conflicts:
	lib/private/Repair/MoveAvatarOutsideHome.php
	lib/private/User/Manager.php
	tests/lib/User/ManagerTest.php
elie195 pushed a commit to elie195/core that referenced this pull request Mar 23, 2017
* introduce callForSeenUsers and countSeenUsers

* add tests

* oracle should support not null on clob

* since 9.2.0
@lock

lock Bot commented Aug 4, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants