简体   繁体   English

减少数据库往返

[英]Reducing database round trip

I have an option in my application where some data has search based on the text which input in a textbox. 我的应用程序中有一个选项,其中一些数据基于在文本框中输入的文本进行搜索。

So I do perform search (Call a stored procedure which take string as input) on textbox text- change event. 因此,我确实在文本框text- change事件上执行了搜索(调用以字符串为输入的存储过程)。

I have reading an article about Improving ADO.NET Performance where I found reducing round trip to database can increase performance. 我读了一篇有关提高ADO.NET性能的文章,发现减少往返数据库的访问可以提高性能。

Is there any better approach for these kinds of situations? 对于这种情况,是否有更好的方法?

Not sure if it suits your requirement but you can make a database call and load desired table/s into a dataset and then make calls to dataset locally. 不确定是否满足您的要求,但是您可以进行数据库调用并将所需的表加载到数据集中,然后在本地对数据集进行调用。 If you introduce a delay in firing an event on text change using timer then you are done with your requirement and everything should be fast. 如果在使用计时器触发文本更改事件时引入延迟,那么您已经满足了您的要求,一切应该很快。 We are using this approach in our application and it serves great. 我们正在应用程序中使用这种方法,它很有用。

But on other hand, I would like to highlight even this approach is not a great deal to enhance performances. 但是,另一方面,我想强调一点,即使这种方法对提高性能也没有多大帮助。 Applications are fast based on their architecture and flow, provided application is considerable in size. 如果应用程序的大小相当大,则基于它们的体系结构和流程,应用程序会很快。 But it always great to think of shortcuts in technology. 但是想到技术的捷径总是很棒的。

depends on your desired user experiance if every change of the textbox has to trigger an update there is little else you can do. 如果文本框的每次更改都必须触发更新,则取决于您期望的用户体验,您几乎无能为力。 textchanged should not fire for every letter typed but only after the user leaves the textbox and the value has changed 只有在用户离开文本框且值已更改后,textchanged才应针对每个键入的字母不触发

if the user can search on multiple fields but the search behind a button 如果用户可以在多个字段上进行搜索,但在按钮后面进行搜索

if this function is used alot and there is not to much data that is rather static you could cache the data in your application and fetch from cache 如果大量使用此功能并且没有太多静态数据,则可以将数据缓存在应用程序中并从缓存中获取

You leave some guessing as don't know what is returned by search. 由于您不知道搜索返回的内容,因此您可能会做出一些猜测。

You could read the data into a Dictionary where key is the textbox input and value is what the search returns. 您可以将数据读入Dictionary中,其中key是文本框输入,而value是搜索返回的内容。 Then you can use LINQ to search the key. 然后,您可以使用LINQ搜索密钥。

What about using an search indexing implementation? 如何使用搜索索引实现? I did this for a very similar problem. 我这样做的原因非常相似。

Upon starting my application, I would prime the Lucene index. 启动我的应用程序后,我将启动Lucene索引。 The index would be refreshed periodically to accomodate changes. 索引将定期刷新以适应更改。

http://www.codeproject.com/Articles/29755/Introducing-Lucene-Net http://www.codeproject.com/Articles/29755/Introducing-Lucene-Net

This is much faster than direct DB calls and is less load on your DB server since the index just has to be primed. 这比直接DB调用要快得多,并且由于只需准备索引,因此DB服务器上的负载更少。 Moreover, Lucene supports a very strong set of search criteria. 此外,Lucene支持非常强大的搜索条件集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM