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

Garbage collector act as a black box #160

Open
lekoala opened this issue Jul 11, 2023 · 1 comment
Open

Garbage collector act as a black box #160

lekoala opened this issue Jul 11, 2023 · 1 comment

Comments

@lekoala
Copy link
Contributor

lekoala commented Jul 11, 2023

This is something I've mentioned here #153 already, but I feel that it's worth to discuss it as a distinct issue.

At the moment, the GarbageCollector acts as a black box. You can collect, and you don't know in advance if it will do something or if it did anything.

This leads to two issues:

  • it makes reporting difficult (did the collect method achieved something?)
  • you don't know in advance if it will work properly (eg: if you have a large number of records)

Ideally, I think the various types of objects to be collected should be accessible from outside the service (maybe static getters on the login session? or as static methods on the garbage collector itself). This way, you can check how many sessions will be collected before calling ->collect(). This can be useful also to get some idea of the current state of the system (eg: do I have any session waiting to be collected?)

Then, I think that the collect method, instead of returning void, could return some kind of result. In the other issue, I've shown an example where it returns an array with a counter for each method, but it could be a result object. Or, if the signature of the collect method cannot be changed, maybe add a "getResults" method with the results of the latest collect method call.

@lekoala
Copy link
Contributor Author

lekoala commented Jan 26, 2024

currently it's also kind of hard to get a full overview of all session about to be collected (since the logic is split accross three functions that you need to merge together in order to get a full list)

here is some sample code to get that in one go if anyone is interested

        $maxAge = LoginSession::getMaxAge();
        $nowTs = DBDatetime::now()->getTimestamp();
        $now = date('Y-m-d H:i:s', $nowTs);

        $case1 = "(LastAccessed < '$maxAge' AND Persistent = 0)";
        $case2 = "(Persistent = 1 AND RememberLoginHash.ExpiryDate < '$now')";
        $case3 = "(LastAccessed < '$maxAge' AND Persistent = 1 AND RememberLoginHash.ExpiryDate IS NULL)";

        $list = LoginSession::get()->leftJoin('RememberLoginHash', 'RememberLoginHash.LoginSessionID = LoginSession.ID');
        $list = $list->where("$case1 OR $case2 OR $case3");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants