Ark_IT
-
3/9/2010 3:03:10 AM
RE:Perfomance, cache and expensive queries
Hello,
As i said - changes take only queries to my catalogue, wich consist branches like /Catalogue/n12345/n1245/n..... and each branch always end wit /tn_21212121....(somenumber) - i called it trade-name, it consist of several (1 or more) SKU.
Document "mydoc" (forexample) Query - cms.document.selectdocuments (runs several times, i cannot change it in kentico webinterface)
important moments commented with //***
1. App_Code/Global/CMS/CMSApplication.cs public static class CMSApplication { /// <summary> /// Fires before the application start event /// </summary> public static void BeforeAplicationStart(object sender, EventArgs e) { // Add your custom actions CMS.SettingsProvider.SqlHelperClass.OnBeforeExecuteQuery += new CMS.SettingsProvider.SqlHelperClass.BeforeExecuteQueryEventHandler(BeforeExecuteQuery); }
static void BeforeExecuteQuery(CMS.SettingsProvider.QueryParameters query, CMS.IDataConnectionLibrary.IDataConnection conn) {
if (query.Name != null) {
switch (query.Name.ToLower()) {
case "cms.document.selectdocuments":
//***if (query.Text.Contains("tn_")) - its a trade-name in catalogue
if ((query.Where.ToString().Contains("tn_")) && ((query.TopN == 1) || (query.TopN == 20))) { string idtradename = query.Where.Substring(query.Where.IndexOf("tn_") + 3, query.Where.IndexOf("'", query.Where.IndexOf("tn_") + 1, query.Where.Length - query.Where.IndexOf("tn_") - 1) - query.Where.IndexOf("tn_") - 3); //*** some handles witn string to get number after "tn_" //*** change query to stored procedure! query.Type = CMS.IDataConnectionLibrary.QueryTypeEnum.StoredProcedure; query.Text = "Proc_CMS__tn_selectdocuments";
object[,] parameters = new object[1, 3]; parameters[0, 0] = "@idtradename"; parameters[0, 1] = idtradename;
query.Params = parameters;
} else if (query.Where.ToString().Contains("/%'")) { //*** this query gets all the nodes UNDER current? so it always use LIKE and take lot of time //*** so change it to search with nodeid - (!important) - nodeid is in branch name, number after "/n" - thats why i told this method is maybe for me only. //*** its DocumentNamePath - and i use other, more userfriendly DocumentUrlPath for documents string idnode = query.Where.Remove(query.Where.IndexOf("%") - 1).Substring(query.Where.LastIndexOf("/n") + 2); query.Type = CMS.IDataConnectionLibrary.QueryTypeEnum.StoredProcedure; query.Text = "Proc_CMS__tn_selectdocuments_prc";
object[,] parameters = new object[2, 3]; parameters[0, 0] = "@idnode"; parameters[0, 1] = idnode; parameters[1, 0] = "@nodeclassid"; parameters[1, 1] = "2160";
query.Params = parameters;
}
break; //*** maybe not to break and add the same to other cases
}
} } .............
2. Stored Procedures includes some searching in other databases and so on. The main query is like this
SELECT View_CMS_Tree_Joined.*, MY_TradeName.* FROM View_CMS_Tree_Joined INNER JOIN My_TradeName ON View_CMS_Tree_Joined.DocumentForeignKeyValue = My_TradeName.[TradeNameID] //*** foreinkey is tradename WHERE nodeparentid= @NodeId and NodeClassID = @nodeclassid //*** query with number-seacrh, no text seacrh
This query works very fast, and all code before it does the same.
|