Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize template addition & update by cross checking the content with system default templates #257

Conversation

darshanasbg
Copy link
Contributor

@darshanasbg darshanasbg commented Sep 2, 2024

Proposed changes in this pull request

$subject. Improves #256 along with renaming,
DefaultTemplateManager to UnifiedTemplateManager
InMemoryBasedTemplateManager to SystemDefaultTemplateManager

Related to,

Main logical change

Main logical change of this PR is focused to the UnifiedTemplateManager.addOrUpdateNotificationTemplate() method.

This implementation changed in a way that, if the org template that is going to be added have same content as a system default template, don't proceed with persisting in a persistent storage, since its redundant. There is no change on the persistent logic for application templates.

Note that, above change to UnifiedTemplateManager.addOrUpdateNotificationTemplate() method only a implementation change and does not change the behavior for any of its outside clients.

Expected behavior for external clients:

For a given scenario lets denote,

  • System default template as c0
  • Template that passed in the addOrUpdateNotificationTemplate() param as c1
  • Template that in the persistent storage as c2
  1. Scenario 1: Adding a template which has same content as system default template
    ie: c1=c0, c2=null
    Expected result: After completing the operation, get template returns c0(=c1).
  2. Scenario 2: Adding a different template compared to the system default template
    ie: c1!=c0, c2=null
    Expected result: After completing the operation, get template returns c1.
  3. Scenario 3: Updating template content to have the same content as system default template different template
    ie: c1=c0, c2!=null
    Expected result: Before the update get template returned c2, after the update get template returns c0(=c1).
  4. Scenario 4: Updating template content to have the different content as system default template different template
    ie: c1!=c0, c2!=null
    Expected result: Before the update get template returned c2, after the update get template returns c1.

This behavior kept same before and after this PR.

Actual change

  1. Scenario 1: Adding a template which has same content as system default template
    ie: c1=c0, c2=null
    Previous impl: c1 stored in the persistent storage which makes c2=c1(=c0)
    New impl: skipping storing c1 which keeps c2=null
  2. Scenario 2: Adding a different template compared to the system default template
    ie: c1!=c0, c2=null
    Previous impl: c1 stored in the persistent storage which makes c2=c1
    New impl: (no change) c1 stored in the persistent storage which makes c2=c1
  3. Scenario 3: Updating template content to have the same content as system default template different template
    ie: c1=c0, c2!=null
    Previous impl: c2 updated in the persistent storage to be c1 which makes c2=c1(=c0)
    New impl: c2 is deleted in the persistent storage which makes c2=null
    Expected result: Before the update get template returned c2, after the update get template returns c0(=c1).
  4. Scenario 4: Updating template content to have the different content as system default template different template
    ie: c1!=c0, c2!=null
    Previous impl: c2 updated in the persistent storage to be c1 which makes c2=c1
    New impl: (no change) c2 updated in the persistent storage to be c1 which makes c2=c1

When should this PR be merged

Immediate.

Follow up actions

N/A

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/10660876790

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/10660876790
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/10660876790

JeethJJ
JeethJJ previously approved these changes Sep 2, 2024
@darshanasbg darshanasbg marked this pull request as ready for review September 2, 2024 13:38
@darshanasbg darshanasbg force-pushed the OptimizeSystemTemplateManagement branch from aedcee2 to af62d1e Compare September 2, 2024 14:07
@darshanasbg darshanasbg requested a review from JeethJJ September 2, 2024 14:07
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 19.30%. Comparing base (4c1521b) to head (8cf3bf4).
Report is 15 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #257      +/-   ##
============================================
+ Coverage     18.02%   19.30%   +1.28%     
- Complexity      170      181      +11     
============================================
  Files            53       52       -1     
  Lines          2869     2833      -36     
  Branches        323      323              
============================================
+ Hits            517      547      +30     
+ Misses         2309     2242      -67     
- Partials         43       44       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

JeethJJ
JeethJJ previously approved these changes Sep 2, 2024
@darshanasbg darshanasbg force-pushed the OptimizeSystemTemplateManagement branch from b6ac39c to c0884ff Compare September 3, 2024 10:56
@darshanasbg darshanasbg force-pushed the OptimizeSystemTemplateManagement branch 2 times, most recently from e2f9e2e to 35b4d7a Compare September 4, 2024 05:29
@darshanasbg darshanasbg force-pushed the OptimizeSystemTemplateManagement branch from 35b4d7a to d1dcf5b Compare September 4, 2024 05:35
JeethJJ
JeethJJ previously approved these changes Sep 4, 2024
@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/10696508535

@@ -39,7 +39,7 @@
* This class have support for get, list, exists operations and any invocations to modification operations
* throws {@link UnsupportedOperationException}.
* This class expected to be use only with conjunction with another {@link TemplatePersistenceManager} implementation
* which supports full CRUD operations, hence {@link DefaultTemplateManager} provides that aggregation using this as a
* which supports full CRUD operations, hence {@link UnifiedTemplateManager} provides that aggregation using this as a
* fallback provider.
*/
public class InMemoryBasedTemplateManager implements TemplatePersistenceManager {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming this to SystemDefaultTemplateManager would make much sense IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.. I also thought InMemoryBasedTemplateManager name only gives the unnecessary implementation detail yet not describe the duty of this class.. Will fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 8cf3bf4

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/10696508535
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/10696508535

@darshanasbg darshanasbg merged commit 59e65e8 into wso2-extensions:master Sep 4, 2024
4 checks passed
@darshanasbg darshanasbg deleted the OptimizeSystemTemplateManagement branch September 4, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants