Need to remove user activity from jira history and activity

Aamir Mulla August 12, 2012

As the question...for a specific user using a Jython script

I have tried using the [UserHistoryManager Class|http://docs.atlassian.com/software/jira/docs/api/4.2/com/atlassian/jira/user/UserHistoryManager.html ], but have been unsucessful.

We are using Jira v4.4.5

3 answers

1 vote
David Chan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 13, 2012

This is something that is definitely not recommended. It may be possible to do this via the database access.

Definitely Backup your database first.

I believe the tables you'll want to take a look at are the:

  • changeitem
  • changegroup
  • userhistoryitem
0 votes
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 8, 2021

I clean like this

def isPreview = true
/*
    That script clean last view activity,
    just in case it was related to the performance degradation in Jira Service Desk and Jira Software for the 10k+
 */
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.UserHistoryItem;
import com.atlassian.jira.user.UserHistoryManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.UserHistoryItem.*;
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.gonchik.scripts.groovy.cleanupLastViewHistoryForInactiveUsers")
log.setLevel(Level.DEBUG)

boolean cleanForActiveUsers = false
// This script shows how to clean up the history items from inactive users
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class)
UserSearchParams userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).includeActive(cleanForActiveUsers).includeInactive(true).maxResults(100000).build()
def userHistoryManager = ComponentAccessor.getComponent(UserHistoryManager.class)
def sb = new StringBuilder()
for (ApplicationUser appUser : userSearchService.findUsers("", userSearchParams)) {
    List<UserHistoryItem> recentUserHistory = userHistoryManager.getHistory(UserHistoryItem.ASSIGNEE, appUser);
    if (!isPreview){
        userHistoryManager.removeHistoryForUser(appUser)
    }
    sb.append("${appUser.name}<br/>\n")
}
return sb.toString()

https://github.com/gonchik/cleanup-scripts/blob/master/groovy/jira/users/cleanUserHistoryLastView.groovy

0 votes
Aamir Mulla October 9, 2012

Thanks for your response David. We have a custom field to gather information about about a tree of improvements under a given feature (done via Jython). It makes some time computations in the process via a virtual (not a person) user account. The problem is the flooding of information in the history due to this. Wonder if anyone knows a Jython or Java based solution for this problem, than at database level.

I have already found out the tables affected by the change, but thanks for re-assuring the list.

Suggest an answer

Log in or Sign up to answer