-
Notifications
You must be signed in to change notification settings - Fork 26
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
Preferences model are locked to single user because of model caching #32
Comments
Hi @TheRND, thanks for pointing that out! I'll fix it as soon as I can. |
Hi @TheRND, Thanks again for pointing this out! |
The better way, probably, is to cache model, but implement setter method and explicitly set userId on retrieval in Dirver::getPreferencesModel($userId)? |
Oh that could be a good idea, you mean something like this: /**
* @param $userId
* @return PreferenceModel
*/
public function getPreferenceModel($userId)
{
if (!isset($this->models[PreferenceModel::class][$userId])) {
$this->models[PreferenceModel::class][$userId] = new PreferenceModel($this->container['client'], $userId);
}
return $this->models[PreferenceModel::class][$userId];
} so every instance of a user id is cached. I wonder, however, if it does not overload the memory where there are many retrieval with different user ids. |
Not exactly, I meant something like this:
So we've got single instance cached and kept getPreferenceModel($userId) method signature for backward compatibility |
Great! I like it, I will implement your solution this weekend. |
Done 😊 |
Now admin user can't set preferences for different users, because Preferences model constructor has userId parameter and it's instance cached then. So getPreferencesModel with different userId is simply ignored, which is not correct. I'm suggesting you to remove userId from constructor and move it to method parameters, or respect userId constructor parameter while caching model.
The text was updated successfully, but these errors were encountered: