如何在Laravel中过滤缓存的查询 [英] How to filter cached query in Laravel

查看:220
本文介绍了如何在Laravel中过滤缓存的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要有关此概念的帮助/建议.我有一个非常复杂的流利查询,该查询根据用户过滤器提取行.

Need help/advice with this concept. I have pretty complex fluent query which pulls rows according to users filters.

我当时正在考虑将要缓存的未过滤查询(仅联接,而没有where/whereIns),然后以某种方式根据用户需要过滤该缓存查询.

I was thinking of making unfiltered (only joins, without where/whereIns) query which would be cached, and then somehow filter that cached query according to users need.

每次表单过滤器更改时,查询db都有2-3秒的延迟,因此我猜测这样做的效果会更好.

There's 2-3 seconds lag when querying db each time form filter changes, so i'm guessing this can perform better.

现在,未经过滤的查询大约有5k行,而经过过滤的查询平均可以带来500-1000行.

Now unfiltered query is around 5k rows, and average filtered one brings 500-1000 rows.

查询大约有25列,其中包含4个CONCATS,3个CASE语句和14个leftJoins.

Query is around 25 columns with 4 CONCATS, 3 CASE statements and 14 leftJoins.

那是正确的方法吗?还有其他建议吗?

Is that right way? Any other suggestions?

提前谢谢!

Y

推荐答案

也许您可以使用 sql视图.

或者您可以将过滤后的数据存储到另一个数据库表中.您可以自动使用触发对其进行更新.

Or you can store your filtered data to another database table. And you can update it using a trigger automatically.

通过这种方式,您可以使用sql快速从数据库表中过滤数据.

By the way you can filter your data fastly from database table using sql.

这将类似于dbcache,但您将对其进行控制.

It will be like dbcache, but you will control it.

这篇关于如何在Laravel中过滤缓存的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆