I have successfully implemented #3 without using any jquery plugin. Due to the way UpdatePanel works, I doubt that it would fix the high cpu usage issue by stopping the "time ago" update via AJAX (i.e. as long as the UpdatePanel is still there, the PostBacks will be executed).
I have tried many approaches to solve this high cpu usage problem and none really solved the problem completely. I ended up with #3 as the solution and it did solved the problem. My solution is not ideal but it is a must for me since many users are complaining the forum locks up overnight and caused their PC to consume more power.
I hope someone more familiar with the code can come up with a real solution in the next release. The info below will help with coming up with the real solution to this problem.
1. The shoutbox UpdatePanel will cause a PostBack every 3 seconds. This is a full-brown PostBack that will cause Forum_Load method to run. Avoid doing expensive work in this method by detecting that it's a async-postback and perform minimal amount of work needed to update the shoutbox panel. Detection code:
System.Web.UI.ScriptManager sm =
System.Web.UI.ScriptManager.GetCurrent(this.Page);
if (sm != null && sm.IsInAsyncPostBack)
{
//This is a post back caused by UpdatePanel.
}
2. During shoutbox UpdatePanel postback, don't need to start another "timeago" javascript instant.
private void PageContext_PageLoad([NotNull] object sender, [NotNull] EventArgs e)
{
//Tommy: don't process on partial update (i.e. shoutbox).
System.Web.UI.ScriptManager sm =
System.Web.UI.ScriptManager.GetCurrent(PageContext.CurrentForumPage.Page);
if (sm != null && sm.IsInAsyncPostBack)
return;
if (PageContext.BoardSettings.ShowRelativeTime &&
!this.PageContext.Vars.ContainsKey("RegisteredTimeago"))
{
YafContext.Current.PageElements.RegisterJsResourceInclude("timeagojs", "js/jquery.timeago.js");
YafContext.Current.PageElements.RegisterJsBlockStartup("timeagoloadjs", JavaScriptBlocks.TimeagoLoadJs);
this.PageContext.Vars["RegisteredTimeago"] = true;
}
}
So why is my current solution not ideal? Well, I basically make the Shoutbox "disappear" after 15 minute of non-chat activity (i.e. not sending any message to the shoutbox). Using a jquery plugin to detect idle is better. Also, instead of making the Shoutbox totally disappear, it might be better to leave it but put up a message that said "Click here when you are back to see the shoutbox again". This requires some jquery/javascript coding to do.
Here are the screenshots showing my solution working. Sorry I'm reusing the images I made for other purposes to save time so please ignore the bubbles.
Shoutbox in Operational State (visible):
Shoutbox after 15 minutes of non-chat activity (completely gone from view):
Edited by user
13 years ago |
Reason: Not specified