Skip to content

Commit

Permalink
SAK-47205 Backfill all existing poll options' order based on their or…
Browse files Browse the repository at this point in the history
…iginal ID quartz job may cause excessive Garbage Collection (sakaiproject#10471)
  • Loading branch information
austin48 authored Apr 27, 2022
1 parent cf4b59d commit a4946c6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public interface PollListManager extends EntityProducer {
*/
public boolean deletePoll(Poll t) throws SecurityException, IllegalArgumentException;

/**
* Gets all the Polls
* @return - a collection of task objects (empty collection if none found)
*/
public List<Poll> findAllPolls();

/**
* Gets all the task objects for the site
* @param siteId - the siteId of the site
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,68 +72,59 @@ public void execute( JobExecutionContext jobExecutionContext ) throws JobExecuti
log.info( "Attempting to back-fill all existing Poll option orders..." );
int modifiedCount = 0;

// Iterate over sites in the system, ordered by creation date...
List<Site> sites = siteService.getSites( SelectionType.ANY, null, null, null, SortType.CREATED_ON_DESC, null );
if( !CollectionUtils.isEmpty( sites ) )
List<Poll> pollsForSite = pollService.findAllPolls();
if( !CollectionUtils.isEmpty( pollsForSite ) )
{
for( Site site : sites )
// Iterate over the polls for the site...
for( Poll poll : pollsForSite )
{
String siteID = site.getId();
List<Poll> pollsForSite = pollService.findAllPolls( siteID );
if( !CollectionUtils.isEmpty( pollsForSite ) )
try
{
// Iterate over the polls for the site...
for( Poll poll : pollsForSite )
// Iterate over Options in the poll...
securityService.pushAdvisor( YES_MAN );
List<Option> pollOptions = pollService.getOptionsForPoll( poll );
if( !CollectionUtils.isEmpty( pollOptions ) )
{
try
// Check if any options have a null order
boolean hasNullOptionOrder = false;
for( Option option : pollOptions )
{
// Iterate over Options in the poll...
securityService.pushAdvisor( YES_MAN );
List<Option> pollOptions = pollService.getOptionsForPoll( poll );
if( !CollectionUtils.isEmpty( pollOptions ) )
if( option.getOptionOrder() == null )
{
// Check if any options have a null order
boolean hasNullOptionOrder = false;
for( Option option : pollOptions )
{
if( option.getOptionOrder() == null )
{
hasNullOptionOrder = true;
break;
}
}
hasNullOptionOrder = true;
break;
}
}

// If any of the option's order is null, we need to back-fill them
if( hasNullOptionOrder )
{
log.info( "Poll ID {} has options with null order, processing...", poll.getId() );
// If any of the option's order is null, we need to back-fill them
if( hasNullOptionOrder )
{
log.info( "Poll ID {} has options with null order, processing...", poll.getId() );

// Order the list by ID
pollOptions.sort( Comparator.comparingLong( Option::getOptionId ) );
// Order the list by ID
pollOptions.sort( Comparator.comparingLong( Option::getOptionId ) );

// Iterate over the list
for( int i = 0; i < pollOptions.size(); i++ )
{
// Add order based on ID
Option option = pollOptions.get( i );
option.setOptionOrder(i);
pollService.saveOption( option );
modifiedCount++;
log.info( "Option {} ---> new order == {}", option.getId(), i );
}
}
// Iterate over the list
for( int i = 0; i < pollOptions.size(); i++ )
{
// Add order based on ID
Option option = pollOptions.get( i );
option.setOptionOrder(i);
pollService.saveOption( option );
modifiedCount++;
log.info( "Option {} ---> new order == {}", option.getId(), i );
}
}
catch( Exception ex )
{
log.error( "Unexcepted exception", ex );
}
finally
{
securityService.popAdvisor( YES_MAN );
}
}
}
catch( Exception ex )
{
log.error( "Unexcepted exception", ex );
}
finally
{
securityService.popAdvisor( YES_MAN );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ public boolean userCanDeletePoll(Poll poll) {
return false;
}

public List<Poll> findAllPolls() {

Search search = new Search();

List<Poll> polls = dao.findBySearch(Poll.class, search);
return polls;
}

public List<Poll> findAllPolls(String siteId) {

Search search = new Search();
Expand Down

0 comments on commit a4946c6

Please sign in to comment.