phoenix-lib / nova-nested-tree-attach-many

MIT License
35 stars 14 forks source link

Support hasMany and belongsTo problems #12

Closed iveliniliev90 closed 3 years ago

iveliniliev90 commented 3 years ago

Hello! I try to use NestedTreeAttachManyField with belongsTo relations but....

image

can you fix this please.

phoenix-lib commented 3 years ago

Hi, could you share .json file that generates debugbar?

I need to understand what generate so many queries.

veneliniliev commented 3 years ago

in nova index EVERY row generate same toTree and if you have a big tree... that's the result... a very slow index.

phoenix-lib commented 3 years ago

Hi, added simple cache in 1.4.2 version, that does not solve the problem of large trees, but solves the problem of multiple queries on one page.

eboye commented 3 years ago

Hmm, I'm using laravel-eloquent-query-cache and when I update the model that has parent which uses nodetrait in Nova it doesn't update the information but in database it's ok.

I suppose that when I enabled caching with redis, this cache implementation was automatically cached and is never cleared.

If I disable caching by setting cacheFor to 0 everything works

protected static bool $flushCacheOnUpdate = true;
public int $cacheFor = 3600;

is it possible to clear the cache? Some kind of tag or something so that when user saves the child that belongs to nested model it is udated in nova backend?

phoenix-lib commented 3 years ago

@eboye - Well... For relation belongsTo used mechanism with disable EventDispatcher and enable it after save. This is necessary to prevent an endless loop of events and this is cause of problem.

phoenix-lib commented 3 years ago

Need to think about how organize cache invalidation

eboye commented 3 years ago

At the end I made the observer of the product model and on saving event I added flushQueryCache()

  /**
     * Handle the Product "saving" event.
     *
     * @param Product $product
     *
     * @return void
     */
    public function saving( Product $product ) {
        $product->flushQueryCache();
    }

Just a note for anyone else having the same issue as I did.

phoenix-lib commented 3 years ago

@eboye - Hi, added fix for package laravel-eloquent-query-cache in version 1.8.0.

eboye commented 3 years ago

Awesome! Thank you. I'll definitely try it and report back.