Kooboo / CMS

Old Kooboo CMS, Use Kooboo/Kooboo instead.
http://www.kooboo.com
Other
337 stars 222 forks source link

Feature Request : Reusable Data Rule #321

Open sbrickey opened 9 years ago

sbrickey commented 9 years ago

In some pages, I reuse the same query on several views, all of which are added to the same page... this can lead to slow load times, and other DRY related problems when filters need to be adjusted.

It would be nice if I could create data rules/queries that are reusable in multiple views (Perhaps create GlobalDataRuleReference which refers to a DataRuleBase from some dev managed section of "global data rules"?).

Once defined and referenced, the results could be cached/reused for the life of the pageload (unless configured for caching).

EDITS: 2015/04/30 : 5:29PM UTC As a step further, it'd also be nice to be able to ADD to the referenced data rule's query... example: global data rule for all blog articles that are Published... create another data rule (either in a view, or "globally") that sorts DESC by NumberOfTimesArticleHasBeenRead (the "reading" column in the sample site template) to show top 10 articles.

MarkSizer commented 9 years ago

You can already have data rules at the page level. These are processed once before any views are rendered. The outcome of the data rule is stored in the ViewBag and accessible by any views contained on that page. So if I understand correctly, there is already support for what you are requesting?

sbrickey commented 9 years ago

so to give an example... blog posts... I have a view for listing, as well as a view for tags (a string field, not a category), and a view of links by month... three views... same data rule... those views are used on several pages, often with more than one on the same page.

in regards to being stored... when data rules are run (by the DataRuleExecutor), it does indeed check the viewbag... but only by the name of the rule... if those views use different names, it is not (immediately) skipped... in the case that the rule is not skipped, it will check the cache IF the rule is configured to use cache, AND if the PREVIOUS rules used cache (matches should occur regardless of rule names, since the cache key is the actual query logic).

So sure, if each view's data rules are created very carefully, in regards to others, it can reuse... but that's a lot of conditions to hit.

Plus, that doesn't address the value of DRY (Don't Repeat Yourself), and correctly applying changes (such as when I added future publishing to my blog posts, which required adding a filter to the data rules in each view).