CalculatedCFType -> getValueFromIssue called twice

We are using a CustomField of type CalculatedCFType for some of our custom fields which will collect the values of related issues using a jql query. Until now we do return a dummy value within the getValueFromIssue method as it’s called twice in a single request (REST API or issue view).
Is there any way around this so that the value is only calculated once per request? For issues with a low amount of related issues it may not matter, but in case we have to handle > 1000 issues it may slow down the performance too much.
If there is a good example that uses a cache with some invalidation it would be nice too (DC compatible)

1 Like

@m.herrmann not exactly related to your question, but you need to be aware of one thing: if you run a JQL search while getting the field value, that means your custom field will not be indexable/searchable (it can’t have a “search template” associated to it). Because JQL search is not available during re-indexing, and since re-indexing will ask every field of every issue for their value, you won’t be able to calculate the field value at that point.

2 Likes

I just found out how atlassian seems to deal with this in their sources:
jira-project/jira-components/jira-core/src/main/java/com/atlassian/jira/issue/fields/AbstractAggregateDurationSystemField.java

final Map requestCache = JiraAuthenticationContextImpl.getRequestCache();

It does use thie request cache to access a predefined key to check if this value was already generated within the current request.

Until now I couldn’t find out how we could implement a request cache and was not aware that you could use the classes like that. The regular JiraAuthenticationContext does not contain this request cache :confused:

@david2 Good hint. We run into that while we implemented our Java Api for plugins like scriptrunner and checking their documentation, which was quite unexpected at first but comprehensible after some consideration how the index may work.