kartik-v / yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.
http://demos.krajee.com/dynagrid
Other
74 stars 66 forks source link

Enable Cache on DynaGridStore #232

Closed alexforte closed 3 years ago

alexforte commented 3 years ago

Prerequisites

Steps to reproduce the issue

  1. Go to a page where is present DynaGrid
  2. Checkout the Debugger Tool and u'll see at least 2 Duplicates of the same Query on DynaGridStore

Expected behavior and actual behavior

I was expecting that DynaGridStore is stored in Cache because doesn't change so often.

Environment

Browsers

Operating System

Libraries

Isolating the problem

Possible Solution:

I found a solution that i want share with all community. In row 415 of DynaGridStore.php you can change to this:

// Original // $data = (new Query()) // ->select([$s['idAttr'], $s['nameAttr']]) // ->from($s['tableName']) // ->where([$s['dynaGridIdAttr'] => $this->_mstKey, $s['categoryAttr'] => $cat]) // ->all(Yii::$app->$connection);

// Fix Problem $data = Yii::$app->getDb()->cache(function ($connection) use ($s) { $data = (new Query()) ->select([$s['idAttr'], $s['nameAttr']]) ->from($s['tableName']) ->where([$s['dynaGridIdAttr'] => $this->_mstKey, $s['categoryAttr'] => $cat]) ->all($connection); return $data; });

kartik-v commented 3 years ago

Thanks for the suggestion. Could you submit a PR for suggested enhancement?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.