[ 2486831 ] Dashboard auto refresh performance issue

- Regression: context not correct after first auto refresh
This commit is contained in:
Heng Sin Low 2009-03-10 01:53:54 +00:00
parent 610cf9ec64
commit a27e86f006
3 changed files with 35 additions and 4 deletions

View File

@ -99,6 +99,7 @@ public class DPActivities extends DashboardPanel implements EventListener {
String sql = "SELECT COUNT(1) FROM AD_Note " String sql = "SELECT COUNT(1) FROM AD_Note "
+ "WHERE AD_Client_ID=? AND AD_User_ID IN (0,?)" + "WHERE AD_Client_ID=? AND AD_User_ID IN (0,?)"
+ " AND Processed='N'"; + " AND Processed='N'";
int retValue = DB.getSQLValue(null, sql, Env.getAD_Client_ID(Env.getCtx()), Env.getAD_User_ID(Env.getCtx())); int retValue = DB.getSQLValue(null, sql, Env.getAD_Client_ID(Env.getCtx()), Env.getAD_User_ID(Env.getCtx()));
return retValue; return retValue;
} }
@ -171,7 +172,7 @@ public class DPActivities extends DashboardPanel implements EventListener {
@Override @Override
public void refresh(ServerPushTemplate template) public void refresh(ServerPushTemplate template)
{ {
noOfNotice = getNoticeCount(); noOfNotice = getNoticeCount();
noOfRequest = getRequestCount(); noOfRequest = getRequestCount();
noOfWorkflow = getWorkflowCount(); noOfWorkflow = getWorkflowCount();
@ -181,6 +182,13 @@ public class DPActivities extends DashboardPanel implements EventListener {
@Override @Override
public void updateUI() { public void updateUI() {
//don't update if not visible
Component c = this.getParent();
while (c != null) {
if (!c.isVisible())
return;
c = c.getParent();
}
btnNotice.setLabel("Notice : " + noOfNotice); btnNotice.setLabel("Notice : " + noOfNotice);
btnRequest.setLabel("Request : " + noOfRequest); btnRequest.setLabel("Request : " + noOfRequest);
btnWorkflow.setLabel("Workflow Activities : " + noOfWorkflow); btnWorkflow.setLabel("Workflow Activities : " + noOfWorkflow);

View File

@ -17,10 +17,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.adempiere.webui.desktop.IDesktop; import org.adempiere.webui.desktop.IDesktop;
import org.adempiere.webui.session.ServerContext;
import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.util.ServerPushTemplate; import org.adempiere.webui.util.ServerPushTemplate;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
/** /**
* *
@ -74,10 +77,25 @@ public class DashboardRunnable implements Runnable {
*/ */
public void refreshDashboard() public void refreshDashboard()
{ {
ServerPushTemplate template = new ServerPushTemplate(desktop); ServerPushTemplate template = new ServerPushTemplate(desktop);
for(int i = 0; i < dashboardPanels.size(); i++) for(int i = 0; i < dashboardPanels.size(); i++)
{
//make sure context is correct
ServerContext ctx = (ServerContext)template.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX);
if (ctx != null && ServerContext.getCurrentInstance() != ctx)
{
ServerContext.setCurrentInstance(ctx);
}
dashboardPanels.get(i).refresh(template); dashboardPanels.get(i).refresh(template);
}
//make sure context is correct
ServerContext ctx = (ServerContext)template.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX);
if (ctx != null && ServerContext.getCurrentInstance() != ctx)
{
ServerContext.setCurrentInstance(ctx);
}
appDesktop.onServerPush(template); appDesktop.onServerPush(template);
} }

View File

@ -45,17 +45,22 @@ public class ServerPushTemplate {
*/ */
public void execute(IServerPushCallback callback) { public void execute(IServerPushCallback callback) {
boolean inUIThread = Executions.getCurrent() != null; boolean inUIThread = Executions.getCurrent() != null;
boolean desktopActivated = false;
try { try {
if (!inUIThread) { if (!inUIThread) {
//1 second timeout //1 second timeout
Executions.activate(desktop, 1000); if (Executions.activate(desktop, 1000)) {
desktopActivated = true;
} else {
return;
}
} }
callback.updateUI(); callback.updateUI();
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.WARNING, "Server push error="+e.getLocalizedMessage(), e); logger.log(Level.WARNING, "Server push error="+e.getLocalizedMessage(), e);
} finally { } finally {
if (!inUIThread) { if (!inUIThread && desktopActivated) {
Executions.deactivate(desktop); Executions.deactivate(desktop);
} }
} }