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

Cache $model->fields() #21

Closed
deiucanta opened this issue Aug 30, 2018 · 2 comments
Closed

Cache $model->fields() #21

deiucanta opened this issue Aug 30, 2018 · 2 comments

Comments

@deiucanta
Copy link
Owner

  • this would improve performance
  • we can cache it as a collection
  • caching should be inside a static property and based on the class name
@robsontenorio
Copy link
Collaborator

I m not sure if it’s necessary. On real world app it wont be touched most of time.

Just used to make tests.

@deiucanta
Copy link
Owner Author

Currently $model->fields() is called whenever a new model is created. When $model->fields() is called, the Field instances are created again and again. That's why I think we should "cache" them.

public static function getFields()
{
    $model = get_class(static);
    
    if (!isset(static::$fieldsCache[$model])) {
        $instance = new static;
        static::$fieldsCache[$model] = $instance->fields();
    }

    static::$fieldsCache[$model]
}

The code is not tested but you should be able to get the idea.

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

No branches or pull requests

2 participants