JQuery autocomplete - optimization issue

love your thoughts about it.

I am using jQuery autocomplete in an ASP.NET MVC application to retrieve a list of records from a database. I would like to know if there is a better way than how I am doing it now, as follows:

Here is jQuery (I call the GetRecordByName action method with autocomplete)

    $('#tb_name').autocomplete({
        source: 'Home/GetRecordByName',
        minLength: 1, delay: 0,
        select: function (event, ui) {
            // do stuff
        }
    });

On the flip side, I use Linq for Entities in a method to retrieve results from a database:

public JsonResult GetRecordByName(string term)
{
        var data = records
            .Where(dr => dr.Key.StartsWith(term))
            .Select(dr => new { dr, value = dr.Key })
            .Take(5);

        return Json(data, JsonRequestBehavior.AllowGet);
}

Currently it works a little slower (~ 1-2 seconds). Basically, a database has tens of thousands of records in it, and every time you enter a character in a text field, the application gets into the database. I can set it to 2 or 3 characters, but it does not change the speed, and I do not want to require a lot of characters.

, : pageload ( javascript) . , , - - ?

?

UPDATE: , , , EF-. EF "" WHERE sql-; , linq - , , . Doh! .Where , , . , . ! , .

Flickr/ , /, , . OutputCache .

!

+5
4

, , . . , Firebug, , . MVC, , ( ToList , , in-method).

, , , , :

  • SQL Server Management Studio , LINQ to Entities. , ?
  • Windows DNS, , , IE, . IE, Firefox, Hosts.

pageload ( javascript) . , , - - , ?

, . , : , , , . . , 100 , , .

+6

1) , [OutputCache]. , . .. , , .

2) : Jquery

"This widget downloads a list of all of your contacts, in JavaScript, in under 200ms
(this is true even for members with 10,000+ contacts). In order to get this level of 
performance, we had to completely rethink how we send data from the server to the client."

3) , Redis. , .

Redis

+2

, , , StriplingWarrior, . , ajax , .

, , , , < 2/3 ?

+1

, , , - redis, /. , .

0
source

All Articles