Page is too slow when loading using Session DataTable
I'm building a calendar app using your plugin, but it is too slow when loading on the live server. on my local development though, i don't feel a thing. everything is super fast there.
In my code below, I bind the calendar to the calendar object only ONCE in the Page_Load handler. This is the only time all the data from the mysql database is loaded onto the DataTable object.
Everytime an item is selected, the page is reloaded, and if Page is a PostBack it doesnt bind the data to the session datatable. So theoretically, it should behave more faster right? How do I solve this performance issue??
System.Data.DataTable BuildCal (string qcal) {
// Create a DataSet
System.Data.DataSet ds = new System.Data.DataSet();
// Create a DataTable to hold results
System.Data.DataTable dt = new System.Data.DataTable("calendar");
// Add the table to the dataset
ds.Tables.Add(dt);
//Create Columns for data
dt.Columns.Add(new System.Data.DataColumn("event_id", typeof(Int32)));
dt.Columns.Add(new System.Data.DataColumn("cal_id", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("posted_by", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("date_posted", typeof(DateTime)));
dt.Columns.Add(new System.Data.DataColumn("title", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("description", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("location", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("start_time", typeof(DateTime)));
dt.Columns.Add(new System.Data.DataColumn("end_time", typeof(DateTime)));
dt.Columns.Add(new System.Data.DataColumn("coy_id", typeof(Int32)));
if (qcal == "") {
qcal = "SELECT event_id, cal_id, posted_by, ADDTIME(date_posted, '" + Session["GMT"] + ":00') as date_posted, title, description, location, ADDTIME(start_time, '" + Session["GMT"] + ":00') as start_time, ADDTIME(end_time, '" + Session["GMT"] + ":00') as end_time, coy_id FROM matadorsystem.mtd_calendar";
}
/* Checks the state of the connection and closes it if it is open */
if(dbConnection.State == System.Data.ConnectionState.Closed) {
dbConnection.Open();
}
OdbcDataAdapter dataAdapter = new OdbcDataAdapter(qcal, dbConnection);
dataAdapter.Fill(dt);
return dt;
}
protected void BindIndex(int vnd) {
DateTime nowDate;
string qcal="";
Session["dt"] = BuildCal(qcal);
DayPilotCalendarWeek.DataSource = Session["dt"];
DayPilotCalendarWeek.BeginColumnName = "start_time";
DayPilotCalendarWeek.EndColumnName = "end_time";
DayPilotCalendarWeek.NameColumnName = "title";
DayPilotCalendarWeek.PkColumnName = "event_id";
DayPilotCalendarWeek.DataBind();
DayPilotCalendarDay.DataSource = Session["dt"];
DayPilotCalendarDay.BeginColumnName = "start_time";
DayPilotCalendarDay.EndColumnName = "end_time";
DayPilotCalendarDay.NameColumnName = "title";
DayPilotCalendarDay.PkColumnName = "event_id";
DayPilotCalendarDay.DataBind();
//Response.Write(viewmode);
Session["viewmode"] = viewmode;
if (vnd==0 && viewmode != "month" && Session["currday"] == ""){
//Response.Write(Session["currday"]);
nowDate = nowDateUtc.AddHours(Convert.ToDouble(Session["GMT"]));
} else if (vnd == 0 && viewmode!= "month" && Session["currday"] != "") {
//Response.Write(lblTitle.Text);
//Response.Write(Session["currday"]);
nowDate = Convert.ToDateTime((CurrDayShown.Value)).AddDays(0);
} else if (vnd!=0 && viewmode != "month") {
nowDate = Convert.ToDateTime((CurrDayShown.Value)).AddDays(vnd);
} else if (viewmode == "month" && Session["currday"] != "") {
nowDate = Convert.ToDateTime((CurrDayShown.Value)).AddMonths(vnd);
CalendarMain.VisibleDate = nowDate;
} else if (viewmode == "month" && Session["currday"] == "") {
nowDate = nowDateUtc.AddHours(Convert.ToDouble(Session["GMT"]));
CalendarMain.VisibleDate = nowDate;
} else {
nowDate = nowDateUtc.AddHours(Convert.ToDouble(Session["GMT"]));
CalendarMain.VisibleDate = nowDate;
}
//Response.Write(vnd);
int dow = Convert.ToInt32(nowDate.DayOfWeek);
int sDateInt = 0;
if (dow != 0) {
sDateInt= -dow;
}
DateTime sDate = nowDate.AddDays(sDateInt);
DateTime eDate = sDate.AddDays(6);
if (viewmode=="week") {
sDate = nowDate.AddDays(sDateInt);
eDate = sDate.AddDays(6);
DayPilotCalendarWeek.StartDate = sDate;
DayPilotCalendarWeek.EndDate = eDate;
lblTitle.Text = sDate.ToString("dd MMM, yyyy") + " to " + eDate.ToString("dd MMM, yyyy");
CurrDayShown.Value = Convert.ToString(nowDate);
}
if (viewmode=="day") {
sDate = nowDate;
DayPilotCalendarDay.StartDate = sDate;
DayPilotCalendarDay.EndDate = sDate;
lblTitle.Text = sDate.ToString("dd MMM, yyyy");
CurrDayShown.Value = sDate.ToString();
}
if (viewmode=="month") {
sDate = nowDate;
lblTitle.Text = sDate.ToString("MMMM yyyy");
CurrDayShown.Value = sDate.ToString();
}
if (viewmode=="agenda") {
sDate = nowDate;
lblTitle.Text = sDate.ToString("dd MMM, yyyy");
CurrDayShown.Value = sDate.ToString();
drawAgenda();
}
}
Asked by rul 5 years ago.