You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by re...@apache.org on 2023/06/05 08:04:25 UTC

[wicket] 01/01: [WICKET-7059] make easier to skip some page serialization

This is an automated email from the ASF dual-hosted git repository.

reiern70 pushed a commit to branch improvement/ernestosemedt/WICKET-7059
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 22bc9fbfd63a65f9714e0ffa4329adf42aaaef28
Author: reiern70 <re...@gmail.com>
AuthorDate: Mon Jun 5 11:03:17 2023 +0300

    [WICKET-7059] make easier to skip some page serialization
---
 .../org/apache/wicket/pageStore/RequestPageStore.java | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java
index c8034f5f4a..d3a4244531 100644
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java
+++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java
@@ -21,6 +21,7 @@ import java.util.LinkedList;
 
 import org.apache.wicket.MetaDataKey;
 import org.apache.wicket.page.IManageablePage;
+import org.apache.wicket.request.IRequestCycle;
 import org.apache.wicket.request.cycle.RequestCycle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -107,9 +108,10 @@ public class RequestPageStore extends DelegatingPageStore
 	public void detach(IPageContext context)
 	{
 		RequestData requestData = getRequestData(context);
+		IRequestCycle requestCycle = RequestCycle.get();
 		for (IManageablePage page : requestData.pages())
 		{
-			if (isPageStateless(page) == false)
+			if (isPageStateless(page) == false && shouldSerializePage(requestCycle, page))
 			{
 				getDelegate().addPage(context, page);
 			}
@@ -119,6 +121,21 @@ public class RequestPageStore extends DelegatingPageStore
 		getDelegate().detach(context);
 	}
 
+	/**
+	 * Give the opportunity to skip some serializations. E.g. we have some AJAX behavior that is sending some
+	 * info from client to page but page structure didn't change at all and nothing is repainted via AJAX.
+	 * But this will trigger a serialization. Returning false here would prevent that request from doing a
+	 * page serialization. For heavy pages this can really make a difference.
+	 *
+	 * @param requestCycle The request
+	 * @param page         The {@link IManageablePage}
+	 * @return <code>true</code> if page should be serialized for this request. The default is true.
+	 */
+	protected boolean shouldSerializePage(IRequestCycle requestCycle, IManageablePage page)
+	{
+		return true;
+	}
+
 	private boolean isPageStateless(final IManageablePage page) {
 		boolean isPageStateless;
 		try