From 894996ca93020f6ab77cb95f769a9df7968f32e2 Mon Sep 17 00:00:00 2001 From: Jeremy Deloche Date: Wed, 30 Jul 2025 11:57:07 +0200 Subject: [PATCH] LUT-29904 : Forms multiview cache --- .../plugins/forms/business/IQuestionDAO.java | 8 ++-- .../plugins/forms/business/QuestionDAO.java | 8 ++-- .../plugins/forms/business/QuestionHome.java | 37 ++++++++++++++----- .../plugins/forms/business/StepHome.java | 12 +++++- .../service/cache/FormsCacheService.java | 15 ++++++++ 5 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/java/fr/paris/lutece/plugins/forms/business/IQuestionDAO.java b/src/java/fr/paris/lutece/plugins/forms/business/IQuestionDAO.java index acb14041d..3436ba534 100644 --- a/src/java/fr/paris/lutece/plugins/forms/business/IQuestionDAO.java +++ b/src/java/fr/paris/lutece/plugins/forms/business/IQuestionDAO.java @@ -129,11 +129,11 @@ public interface IQuestionDAO List selectQuestionsList( Plugin plugin ); /** - * Load the data of all the question objects and returns them as a list + * Load the data of the question objects related to multiview and returns them as a list * * @param plugin * the Plugin - * @return The list which contains the uncomplete data of all the question objects + * @return The list which contains the uncomplete data of the question objects related to multiview */ List selectQuestionsListUncomplete( Plugin plugin ); @@ -160,13 +160,13 @@ public interface IQuestionDAO List selectQuestionsListByFormId( int nIdForm, Plugin plugin ); /** - * Load the data of all the question objects by form id and returns them as a list + * Load the data of the question objects related to multiview by form id and returns them as a list * * @param nIdForm * The id of the form * @param plugin * The plugin - * @return The list which contains the data of all the question objects by given form id + * @return The list which contains the data of the question objects related to multiview by given form id */ List selectQuestionsListByFormIdUncomplete( int nIdForm, Plugin plugin ); diff --git a/src/java/fr/paris/lutece/plugins/forms/business/QuestionDAO.java b/src/java/fr/paris/lutece/plugins/forms/business/QuestionDAO.java index 3501ad830..60d7a4079 100644 --- a/src/java/fr/paris/lutece/plugins/forms/business/QuestionDAO.java +++ b/src/java/fr/paris/lutece/plugins/forms/business/QuestionDAO.java @@ -64,7 +64,9 @@ public final class QuestionDAO implements IQuestionDAO private static final String SQL_QUERY_SELECT_BY_STEP = SQL_QUERY_SELECT_ALL + " WHERE id_step = ?"; private static final String SQL_QUERY_SELECTALL_BY_FORM = "SELECT fq.id_question, fq.title, fq.code, fq.description, fq.id_entry, fq.id_step, fq.is_visible_multiview_global, fq.is_visible_multiview_form_selected , fq.column_title, fq.is_filterable_multiview_global, fq.is_filterable_multiview_form_selected,fq.multiview_column_order,fq.export_display_order FROM forms_question fq INNER JOIN forms_step fs ON fq.id_step = fs.id_step WHERE fs.id_form = ?"; private static final String SQL_QUERY_SELECT_IN = SQL_QUERY_SELECT_ALL + " WHERE id_question IN ( "; - + private static final String SQL_QUERY_SELECT_ALL_UNCOMPLETE = SQL_QUERY_SELECT_ALL + " where (is_visible_multiview_global = '1' or is_filterable_multiview_global = '1')"; + private static final String SQL_QUERY_SELECT_BY_STEP_UNCOMPLETE = SQL_QUERY_SELECTALL_BY_FORM + " and (is_visible_multiview_global = '1' or is_visible_multiview_form_selected = '1' or is_filterable_multiview_global = '1' or is_filterable_multiview_form_selected = '1')"; + /** * {@inheritDoc } */ @@ -278,7 +280,7 @@ public List selectIdQuestionsList( Plugin plugin ) public List selectQuestionsListUncomplete( Plugin plugin ) { List questionList = new ArrayList<>( ); - try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALL, plugin ) ) + try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALL_UNCOMPLETE, plugin ) ) { daoUtil.executeQuery( ); @@ -337,7 +339,7 @@ public List selectQuestionsListByFormId( int nIdForm, Plugin plugin ) public List selectQuestionsListByFormIdUncomplete( int nIdForm, Plugin plugin ) { List questionList = new ArrayList<>( ); - try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_BY_FORM, plugin ) ) + try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_STEP_UNCOMPLETE , plugin ) ) { daoUtil.setInt( 1, nIdForm ); daoUtil.executeQuery( ); diff --git a/src/java/fr/paris/lutece/plugins/forms/business/QuestionHome.java b/src/java/fr/paris/lutece/plugins/forms/business/QuestionHome.java index eba657d63..4eed6aa06 100644 --- a/src/java/fr/paris/lutece/plugins/forms/business/QuestionHome.java +++ b/src/java/fr/paris/lutece/plugins/forms/business/QuestionHome.java @@ -72,7 +72,7 @@ private QuestionHome( ) public static Question create( Question question ) { _dao.insert( question, _plugin ); - + _cache.resetCache(); return question; } @@ -86,7 +86,7 @@ public static Question create( Question question ) public static Question update( Question question ) { _dao.store( question, _plugin ); - _cache.removeKey( _cache.getQuestionCacheKey( question.getId( ) ) ); + _cache.resetCache(); return question; } @@ -104,7 +104,7 @@ public static void remove( int nKey ) EntryHome.remove( questionToDelete.getIdEntry( ) ); } _dao.delete( nKey, _plugin ); - _cache.removeKey( _cache.getQuestionCacheKey( nKey ) ); + _cache.resetCache(); } /** @@ -178,13 +178,22 @@ public static List getQuestionsList( ) } /** - * Load the data of all the question objects and returns them as a list + * Load the data of the question objects related to multiview and returns them as a list * - * @return the list which contains the data of all the question objects + * @return the list which contains the data of the question objects related to multiview */ public static List getQuestionsListUncomplete( ) { - return _dao.selectQuestionsListUncomplete( _plugin ); + String cacheKey = _cache.getUncompleteQuestionCacheKey( ); + @SuppressWarnings( "unchecked" ) + List listQuestion = ( List ) _cache.getFromCache( cacheKey ); + if ( listQuestion == null ) + { + listQuestion = _dao.selectQuestionsListUncomplete( _plugin ); + _cache.putInCache( cacheKey, listQuestion ); + } + + return listQuestion; } /** @@ -212,15 +221,25 @@ public static List getListQuestionByIdForm( int nIdForm ) } /** - * Load the data of all the question objects for given form id and returns them as a list + * Load the data of the question objects related to multiview for given form id and returns them as a list * * @param nIdForm * The id of the form - * @return the list of all the question objects for the given form id + * @return the list of the question objects related to multiview for the given form id */ public static List getListQuestionByIdFormUncomplete( int nIdForm ) { - return _dao.selectQuestionsListByFormIdUncomplete( nIdForm, _plugin ); + + String cacheKey = _cache.getUncompleteQuestionByFormCacheKey( nIdForm ); + @SuppressWarnings( "unchecked" ) + List listQuestion = ( List ) _cache.getFromCache( cacheKey ); + if ( listQuestion == null ) + { + listQuestion = _dao.selectQuestionsListByFormIdUncomplete( nIdForm, _plugin ); + _cache.putInCache( cacheKey, listQuestion ); + } + + return listQuestion; } /** diff --git a/src/java/fr/paris/lutece/plugins/forms/business/StepHome.java b/src/java/fr/paris/lutece/plugins/forms/business/StepHome.java index 1ebfbfa16..03478ffcf 100644 --- a/src/java/fr/paris/lutece/plugins/forms/business/StepHome.java +++ b/src/java/fr/paris/lutece/plugins/forms/business/StepHome.java @@ -68,7 +68,7 @@ private StepHome( ) public static Step create( Step step ) { _dao.insert( step, _plugin ); - _cache.putInCache( _cache.getStepCacheKey( step.getId( ) ), step ); + _cache.resetCache( ); return step; } @@ -192,7 +192,15 @@ public static List getIdStepsList( ) */ public static List getIdStepsListByForm( int nIdForm ) { - return _dao.selectIdStepsListByForm( nIdForm, _plugin ); + String stepCacheKey = _cache.getIdStepByFormKey( nIdForm ); + @SuppressWarnings( "unchecked" ) + List listIdStep = ( List ) _cache.getFromCache( stepCacheKey ); + if ( listIdStep == null ) + { + listIdStep = _dao.selectIdStepsListByForm( nIdForm, _plugin ); + _cache.putInCache( stepCacheKey, listIdStep ); + } + return listIdStep; } /** diff --git a/src/java/fr/paris/lutece/plugins/forms/service/cache/FormsCacheService.java b/src/java/fr/paris/lutece/plugins/forms/service/cache/FormsCacheService.java index ce9542af6..329ea276f 100644 --- a/src/java/fr/paris/lutece/plugins/forms/service/cache/FormsCacheService.java +++ b/src/java/fr/paris/lutece/plugins/forms/service/cache/FormsCacheService.java @@ -68,6 +68,11 @@ public String getInitialStepCacheKey( int nIdForm ) return new StringBuilder( "Initial-Step-For-Form-id:" ).append( nIdForm ).toString( ); } + public String getIdStepByFormKey( int nIdQuestion ) + { + return new StringBuilder( "Step-For-Form-id:" ).append( nIdQuestion ).toString( ); + } + public String getFormCacheKey( int nIdForm ) { return new StringBuilder( "Form-id:" ).append( nIdForm ).toString( ); @@ -100,6 +105,16 @@ public String getQuestionCacheKey( int nIdQuestion ) return new StringBuilder( "Question-id:" ).append( nIdQuestion ).toString( ); } + public String getUncompleteQuestionCacheKey( ) + { + return new StringBuilder( "Question-Uncomplete" ).toString( ); + } + + public String getUncompleteQuestionByFormCacheKey( int nIdForm ) + { + return new StringBuilder( "Question-Uncomplete-by-Form:" ).append( nIdForm ).toString( ); + } + public String getFormDisplayCacheKey( int nIdFormDisplay ) { return new StringBuilder( "FormDisplay-id:" ).append( nIdFormDisplay ).toString( );