Hi everyone,
due to the lack of a documented Tempo Timesheets Java API i have created a script runner scripted field that sums up the Tempo field "Billed Time" for an issue using the Tempo Rest API.
This script runs over 100ms when the field is rendered.
This sounds to me like it has the potential for a heavy performance impact.
So i removed it's searcher, restricted the field to a more narrow context and kept it out of any screens.
But the business use case doesnt allow to narrow down the context very far this still feels insufficient,
i can for example see the field is rendered when an app finds a corresponding issue in /rest/api/2/search or someone comments an issue.
Does anyone have a creative idea to restrict the performance impact any further?
How did you guys solve similar problems?
Cheers
Jens
Hi Jens,
I am not an expert in Scriptrunner but maybe you can use something in this direction:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.Worklog
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.core.workattribute.api.WorkAttributeService
import com.tempoplugin.core.workattribute.api.WorkAttributeValueService
@WithPlugin("is.origo.jira.tempo-plugin")
@PluginModule
WorkAttributeService workAttributeService
@PluginModule
WorkAttributeValueService workAttributeValueService
def worklogManager = ComponentAccessor.worklogManager
def worklogs = worklogManager.getByIssue(issue)
def attribute = workAttributeService.getWorkAttributeByKey("Tempo.WorklogBilledHours").returnedValue
worklogs.sum { Worklog worklog ->
workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id).returnedValue
} as Long
Hi Alexander.
thanks that looks awesome.
I will try this out.
You should put that in your public docs if it isnt.
Would also make a nice contribution to the adaptavist libary.
Good Luck for your webinar with Andreas today!
kind regards
Jens
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jens,
will do once you confirmed that it is working (and how).
Keep us posted!
BR
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexander,
i cant get the last few lines to work,
the return value of
workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id).returnedValue
seems to be a
com.tempoplugin.core.workattribute.api.WorkAttributeValue
and i don't know how to access the number of billed time on that object.
Any clues?
kind regards
Jens
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jens,
a hint would be:
getValue()
BR
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alexander,
that hint was helpful.
I've slighty rewritten the end of the script to fall back to the logged time if the billed time is empty and the working version looks like this:
def attribute = workAttributeService.getWorkAttributeByKey("Tempo.WorklogBilledHours").returnedValue
Long sum = 0L
Iterator wlIterator = worklogs.iterator()
while (wlIterator.hasNext()) {
Worklog worklog = wlIterator.next()
def value = workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id).returnedValue
if (value != null) {
Long longValue = Long.parseLong(value.getValue())
sum += longValue
} else {
log.error worklog.getTimeSpent()
sum += worklog.getTimeSpent()
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexander Eck [Tempo] , thanks a lot for your helpful input.
You dont happen to have a similar script ready that allows me to extract expenses via the Java API?
Have a nice weekend.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jens,
no not really. Maybe you can try:
import com.tempoplugin.core.expense.api.Expense;
import com.tempoplugin.core.expense.api.ExpenseService;
getExpensesByScope(@Nonnull ScopeType scopeType, Long... scope)
getExpensesByScopeAndDate(Pair<LocalDate, LocalDate> duration, Expense.ScopeType scopeType, Long... scope)
with ScopeType = ISSUE.
You might also take a look at the REST API documentation.
Have a good one.
BR
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexander Eck [Tempo] thanks for your input again!
We are now looking to do the same for the planned time, do you happen to have a Java code snippet for that as well?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cache the sum (I don't know where to store) and recalculate only if the issue's update date changes?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah thats one option i was considering, i'd make a static groovy class and use that one as a cache.
Cheers
Jens
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.