Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JavaAPI/Scriptrunner - userAccessor takes too long, REST-Endpoint runs into time-out

Stefan Salzl
Community Champion
February 22, 2024

Hi all,

I am running into performance issues within a confluence instance when fetching users data to build a custom endpoint.

Yes the number of users is quit high (2000 users) but I really wonder how the UI is managing when the JavaAPI is not capable.

So what I am trying to do:

  • get users from 3 different groups
  • fetching the user objects
  • building a JSON with several of it´s attributes

The logic works fine and for other groups (there are only a few hundred users) it works (even not really satisfying performance). As soon as fetching user objects kicks in it slows down.

When calling the script via endpoint I´m running into (kinda) timeout:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /rest/scriptrunner/latest/custom/<nameOfEndpoint>.

Reason: Error reading from remote server

 

I built the same functionality in Jira too and the UserUtil doesn´t have any problem with a higher amount of users.

 

See my code from confluence scriptrunner rest-endpoint:

<endpoint>( 

    httpMethod: "GET"

) { MultivaluedMap queryParams, String body ->

    def maGroups = ["group_01", "group_02", "group_03"] as Collection<String>

    def billGroups = userAccessor.getGroupsAsList()?.findAll { it.name.startsWith('verrechnung-') && maGroups.contains(it.name) }

   

    log.warn(billGroups)

    def billUsers = [] as List<String>

    def users = []

    billGroups.each { group ->

        // def billUsers = [] as List<String>

        billUsers.addAll(userAccessor.getMemberNamesAsList(group))

        // log.warn("${group.name}: ${billUsers}")

        log.warn("each: " + group.name)

        log.warn("billUsers: " + billUsers)

        log.warn("billUsers size: " + billUsers.size())

    }

   

    billUsers.each { userName ->

        // def user = Users.getByName(userName)

        def user = userManager.getUser(userName)

        def billGroupsOfUser = userAccessor.getGroupNamesForUserName(user.name).findAll { it.startsWith("verrechnung-") }

        def createdDate = crowdService.getUser(user.name).asType(TimestampedUser).createdDate.format('yyyy-MM-dd')

        def userSpaces = permissionFilter.getPermittedSpaceKeysForUser(user)

       

        users.add([

            billGroup: billGroupsOfUser.join(","),

            userName: user.name,

            fullName: user.fullName,

            email: user.email,

            created: createdDate,

            spaces: userSpaces.join(", ")

        ])

    }

   

    log.warn("users size(): " + users.size())

    def response = [users:users]

    log.warn("response: " + response)

    return Response.ok(new JsonBuilder(response).toString()).build()

}

 

Edit: more facts

Users:

users size(): 879

 

Time:

Elapsed: 34847 ms 

CPU time: 20819 ms

 

 

Any help appreciated.

Thanks in advance.

Best
Stefan

 

1 answer

0 votes
Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2024

Hello @Stefan Salzl ,

Did you check the internal implementation of the Java code - maybe you can compare the one in Jira and Confluence and see why it is so?

There are some other APIs that can be used for accessing user data - maybe they can be more effective if correctly combined :)

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events