Aarti-panchal01 opened a new pull request, #6711:
URL: https://github.com/apache/fineract/pull/6711

   ## Description
   
   `HookReadPlatformServiceImpl.retrieveHooksByEvent(entityName, actionName)` 
is `@Cacheable` with the key `<tenantId>HK`. With an explicit `key`, Spring 
ignores the method arguments, so every event in a tenant shares one cache 
entry, but the result depends on both arguments 
(`HookRepository.findAllHooksListeningToEvent` filters on `entityName` and 
`actionName`).
   
   `FineractHookListener` calls it after every write command. So when the 
"hooks" cache is live, the first command in a tenant fills the entry and, until 
it expires (default TTL 1 minute) or a hook is changed, every other event gets 
that same list. Example: hook A listens to CLIENT/CREATE and hook B to 
LOAN/APPROVE. A client is created first; for the next minute, approving a loan 
fires A with the loan payload and B never fires. If the first command is one no 
hook listens to, the entry is an empty list and no hook fires for any event in 
that window.
   
   The cache is only live when the tenant uses the single-node cache (`PUT 
/caches` with `cacheType: 2`). The default cache type gives "hooks" a no-op 
cache, which is why default installs and the existing hook integration tests do 
not see this.
   
   The key now includes the event: `<tenantId>HK|<entityName>|<actionName>`. 
The tenant is still in the key, and the hook create, update and delete commands 
already evict all entries (`@CacheEvict(allEntries = true)`), so nothing else 
changes.
   
   Added `HookReadPlatformServiceImplCacheTest`, which runs the service through 
a real Spring cache (`@EnableCaching` with a `ConcurrentMapCacheManager`) and a 
mocked `HookRepository`:
   - `secondEventDoesNotGetTheHooksCachedForTheFirstEvent`: CLIENT/CREATE then 
LOAN/APPROVE, each gets its own hooks.
   - `hooksAreStillCachedPerEvent`: calling each event twice reads the 
repository once per event.
   
   Both fail on develop (LOAN/APPROVE gets the CLIENT/CREATE hook) and pass 
with this change.
   
   Side note, not changed here: the cached values are `Hook` JPA entities, 
which outlive the transaction that loaded them. Happy to look at that 
separately if you think it matters.
   
   JIRA: https://issues.apache.org/jira/browse/FINERACT-2981
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request 
- thanks!
   
   - [x] Write the commit message as per [our 
guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
   - [x] Acknowledge that we will not review PRs that are not passing the build 
_("green")_ - it is your responsibility to get a proposed PR to pass the build, 
not primarily the project's maintainers.
   - [x] Create/update [unit or integration 
tests](https://fineract.apache.org/docs/current/#_testing) for verifying the 
changes made.
   - [x] Follow our [coding 
conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions).
   - [ ] Add required Swagger annotation and update API documentation at 
fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with 
details of any API changes
   - [x] [This PR must not be a "code 
dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit).
 Large changes can be made in a branch, with assistance. Ask for help on the 
[developer mailing list](https://fineract.apache.org/#contribute).
   - [x] If merging this PR resolves a JIRA issue, I will mark that issue as 
resolved and set "Fix Version/s" appropriately.
   - [x] I followed the [AI 
Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to