5151import org .labkey .api .pipeline .PipelineJobException ;
5252import org .labkey .api .query .BatchValidationException ;
5353import org .labkey .api .query .FieldKey ;
54+ import org .labkey .api .query .InvalidKeyException ;
5455import org .labkey .api .query .QueryService ;
56+ import org .labkey .api .query .QueryUpdateServiceException ;
5557import org .labkey .api .query .UserSchema ;
5658import org .labkey .api .security .RequiresPermission ;
5759import org .labkey .api .security .User ;
@@ -594,7 +596,7 @@ public boolean handlePost(Object form, BindException errors) throws Exception
594596 {
595597 UserSchema sa = QueryService .get ().getUserSchema (getUser (), getContainer (), SingleCellSchema .SEQUENCE_SCHEMA_NAME );
596598 List <Map <String , Object >> toUpdate = new ArrayList <>();
597- new TableSelector (sa .getTable ("outputfiles" ), PageFlowUtil .set ("rowid" ), new SimpleFilter (FieldKey .fromString ("category" ), "Seurat Object Prototype" ), null ).forEach (Integer .class , rowId -> {
599+ new TableSelector (sa .getTable ("outputfiles" ), PageFlowUtil .set ("rowid" ), new SimpleFilter (FieldKey .fromString ("category" ), "Seurat Object Prototype" ). addCondition ( FieldKey . fromString ( "modified" ), "2025-04-29" , CompareType . DATE_LT ) , null ).forEach (Integer .class , rowId -> {
598600 SequenceOutputFile so = SequenceOutputFile .getForId (rowId );
599601 if (so == null )
600602 {
@@ -645,6 +647,12 @@ public boolean handlePost(Object form, BindException errors) throws Exception
645647
646648 String description = AbstractSingleCellHandler .getOutputDescription (params , _log , so .getFile (), null );
647649 toUpdate .add (new CaseInsensitiveHashMap <>(Map .of ("rowid" , so .getRowid (), "description" , description )));
650+
651+ if (toUpdate .size () % 250 == 0 )
652+ {
653+ doUpdate (toUpdate , getUser (), getContainer ());
654+ toUpdate .clear ();
655+ }
648656 }
649657 catch (PipelineJobException e )
650658 {
@@ -654,25 +662,34 @@ public boolean handlePost(Object form, BindException errors) throws Exception
654662
655663 if (!toUpdate .isEmpty ())
656664 {
657- try
658- {
659- BatchValidationException bve = new BatchValidationException ();
660- List <Map <String , Object >> oldKeys = toUpdate .stream ().map (row -> Map .of ("rowid" , row .get ("rowid" ))).toList ();
661- sa .getTable ("outputfiles" ).getUpdateService ().updateRows (getUser (), getContainer (), toUpdate , oldKeys , bve , null , null );
662-
663- if (bve .hasErrors ())
664- {
665- throw bve ;
666- }
667- }
668- catch (SQLException | BatchValidationException e )
669- {
670- _log .error ("Unable to update outputfiles" , e );
671- return false ;
672- }
665+ doUpdate (toUpdate , getUser (), getContainer ());
666+ toUpdate .clear ();
673667 }
674668
675669 return true ;
676670 }
677671 }
672+
673+ private static void doUpdate (List <Map <String , Object >> toUpdate , User u , Container c )
674+ {
675+ try
676+ {
677+ _log .info ("Total prototype updates: " + toUpdate .size ());
678+
679+ BatchValidationException bve = new BatchValidationException ();
680+ List <Map <String , Object >> oldKeys = toUpdate .stream ().map (row -> Map .of ("rowid" , row .get ("rowid" ))).toList ();
681+
682+ UserSchema sa = QueryService .get ().getUserSchema (u , c , SingleCellSchema .SEQUENCE_SCHEMA_NAME );
683+ sa .getTable ("outputfiles" ).getUpdateService ().updateRows (u , c , toUpdate , oldKeys , bve , null , null );
684+
685+ if (bve .hasErrors ())
686+ {
687+ throw bve ;
688+ }
689+ }
690+ catch (SQLException | InvalidKeyException | QueryUpdateServiceException | BatchValidationException e )
691+ {
692+ _log .error ("Unable to update outputfiles" , e );
693+ }
694+ }
678695}
0 commit comments