Giter VIP home page Giter VIP logo

Comments (7)

gnello avatar gnello commented on July 25, 2024

Hi @TheRND, thanks for pointing that out!
I think is better remove userId from constructor and move it to method parameters, as you said.

I'll fix it as soon as I can.

from php-mattermost-driver.

gnello avatar gnello commented on July 25, 2024

Hi @TheRND,
I finally decided to not cache the model, keeping the "userId" parameter in the constructor. In this way no breaking changes were introduced.

Thanks again for pointing this out!

from php-mattermost-driver.

TheRND avatar TheRND commented on July 25, 2024

The better way, probably, is to cache model, but implement setter method and explicitly set userId on retrieval in Dirver::getPreferencesModel($userId)?

from php-mattermost-driver.

gnello avatar gnello commented on July 25, 2024

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.

from php-mattermost-driver.

TheRND avatar TheRND commented on July 25, 2024

Not exactly, I meant something like this:

/**
     * @param $userId
     * @return PreferenceModel
     */
    public function getPreferenceModel($userId)
    {
        if (!isset($this->models[PreferenceModel::class])) {
            $this->models[PreferenceModel::class] = new PreferenceModel($this->container['client']); // Remove userid from constructor and move it into setter
        }

        return $this->models[PreferenceModel::class]->setUserId($userId); // Transient setter
    }

So we've got single instance cached and kept getPreferenceModel($userId) method signature for backward compatibility

from php-mattermost-driver.

gnello avatar gnello commented on July 25, 2024

Great! I like it, I will implement your solution this weekend.

from php-mattermost-driver.

gnello avatar gnello commented on July 25, 2024

Done 😊

from php-mattermost-driver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.