@@ -103,9 +103,10 @@ public async Task ReleaseAcquiredTimeTickers(Guid[] timeTickerIds, CancellationT
103103 await using var dbContext = await DbContextFactory . CreateDbContextAsync ( cancellationToken ) . ConfigureAwait ( false ) ; ;
104104 var now = _clock . UtcNow ;
105105
106- var baseQuery = timeTickerIds . Length == 0
106+ var idList = timeTickerIds . ToList ( ) ;
107+ var baseQuery = idList . Count == 0
107108 ? dbContext . Set < TTimeTicker > ( )
108- : dbContext . Set < TTimeTicker > ( ) . Where ( x => timeTickerIds . Contains ( x . Id ) ) ;
109+ : dbContext . Set < TTimeTicker > ( ) . Where ( x => idList . Contains ( x . Id ) ) ;
109110
110111 await baseQuery
111112 . WhereCanAcquire ( _lockHolder )
@@ -127,9 +128,15 @@ public async Task<int> UpdateTimeTicker(InternalFunctionContext functionContexts
127128 public async Task UpdateTimeTickersWithUnifiedContext ( Guid [ ] timeTickerIds , InternalFunctionContext functionContext , CancellationToken cancellationToken = default )
128129 {
129130 await using var dbContext = await DbContextFactory . CreateDbContextAsync ( cancellationToken ) . ConfigureAwait ( false ) ; ;
131+ var idList = timeTickerIds . ToList ( ) ;
130132 await dbContext . Set < TTimeTicker > ( )
133+ << < << << HEAD
131134 . Where ( x => timeTickerIds . Contains ( x . Id ) )
132135 . ExecuteUpdateAsync ( MappingExtensions . UpdateTimeTicker < TTimeTicker > ( functionContext , _clock . UtcNow ) , cancellationToken ) . ConfigureAwait ( false ) ;
136+ == = == ==
137+ . Where ( x => idList . Contains ( x . Id ) )
138+ . ExecuteUpdateAsync ( setter => setter . UpdateTimeTicker < TTimeTicker > ( functionContext , _clock . UtcNow ) , cancellationToken ) . ConfigureAwait ( false ) ;
139+ > >>> >>> 39 b9b90 ( Fix . NET 9 + EF Core query failures caused by ReadOnlySpan array. Contains ( ) ( #574 ) )
133140 }
134141
135142 public async Task < TimeTickerEntity [ ] > GetEarliestTimeTickers ( CancellationToken cancellationToken )
@@ -214,10 +221,11 @@ public async Task<TimeTickerEntity[]> AcquireImmediateTimeTickersAsync(Guid[] id
214221
215222 await using var dbContext = await DbContextFactory . CreateDbContextAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
216223 var now = _clock . UtcNow ;
224+ var idList = ids . ToList ( ) ;
217225
218226 // Acquire and mark InProgress in a single update
219227 var affected = await dbContext . Set < TTimeTicker > ( )
220- . Where ( x => ids . Contains ( x . Id ) )
228+ . Where ( x => idList . Contains ( x . Id ) )
221229 . WhereCanAcquire ( _lockHolder )
222230 . ExecuteUpdateAsync ( setter => setter
223231 . SetProperty ( x => x . LockHolder , _lockHolder )
@@ -232,7 +240,7 @@ public async Task<TimeTickerEntity[]> AcquireImmediateTimeTickersAsync(Guid[] id
232240 // Return the acquired tickers for immediate execution, with children
233241 return await dbContext . Set < TTimeTicker > ( )
234242 . AsNoTracking ( )
235- . Where ( x => ids . Contains ( x . Id ) && x . LockHolder == _lockHolder && x . Status == TickerStatus . InProgress )
243+ . Where ( x => idList . Contains ( x . Id ) && x . LockHolder == _lockHolder && x . Status == TickerStatus . InProgress )
236244 . Include ( x => x . Children . Where ( y => y . ExecutionTime == null ) )
237245 . Select ( MappingExtensions . ForQueueTimeTickers < TTimeTicker > ( ) )
238246 . ToArrayAsync ( cancellationToken )
@@ -245,7 +253,7 @@ public async Task MigrateDefinedCronTickers((string Function, string Expression)
245253 await using var dbContext = await DbContextFactory . CreateDbContextAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
246254 var now = _clock . UtcNow ;
247255
248- var functions = cronTickers . Select ( x => x . Function ) . ToArray ( ) ;
256+ var functions = cronTickers . Select ( x => x . Function ) . ToList ( ) ;
249257 var cronSet = dbContext . Set < TCronTicker > ( ) ;
250258
251259 // Build the complete set of registered function names to detect orphaned tickers.
@@ -262,16 +270,17 @@ public async Task MigrateDefinedCronTickers((string Function, string Expression)
262270 . ToArrayAsync ( cancellationToken )
263271 . ConfigureAwait ( false ) ;
264272
265- if ( orphanedCron . Length > 0 )
273+ var orphanedCronList = orphanedCron . ToList ( ) ;
274+ if ( orphanedCronList . Count > 0 )
266275 {
267276 // Delete related occurrences first (if any), then the cron tickers
268277 await dbContext . Set < CronTickerOccurrenceEntity < TCronTicker > > ( )
269- . Where ( o => orphanedCron . Contains ( o . CronTickerId ) )
278+ . Where ( o => orphanedCronList . Contains ( o . CronTickerId ) )
270279 . ExecuteDeleteAsync ( cancellationToken )
271280 . ConfigureAwait ( false ) ;
272281
273282 await cronSet
274- . Where ( c => orphanedCron . Contains ( c . Id ) )
283+ . Where ( c => orphanedCronList . Contains ( c . Id ) )
275284 . ExecuteDeleteAsync ( cancellationToken )
276285 . ConfigureAwait ( false ) ;
277286 }
@@ -421,9 +430,10 @@ public async Task ReleaseAcquiredCronTickerOccurrences(Guid[] occurrenceIds, Can
421430 var now = _clock . UtcNow ;
422431 await using var dbContext = await DbContextFactory . CreateDbContextAsync ( cancellationToken ) . ConfigureAwait ( false ) ; ;
423432
424- var baseQuery = occurrenceIds . Length == 0
425- ? dbContext . Set < CronTickerOccurrenceEntity < TCronTicker > > ( )
426- : dbContext . Set < CronTickerOccurrenceEntity < TCronTicker > > ( ) . Where ( x => occurrenceIds . Contains ( x . Id ) ) ;
433+ var idList = occurrenceIds . ToList ( ) ;
434+ var baseQuery = idList . Count == 0
435+ ? dbContext . Set < CronTickerOccurrenceEntity < TCronTicker > > ( )
436+ : dbContext . Set < CronTickerOccurrenceEntity < TCronTicker > > ( ) . Where ( x => idList . Contains ( x . Id ) ) ;
427437
428438 await baseQuery
429439 . WhereCanAcquire ( _lockHolder )
@@ -524,13 +534,23 @@ public async IAsyncEnumerable<CronTickerOccurrenceEntity<TCronTicker>> QueueCron
524534 public async Task < CronTickerOccurrenceEntity < TCronTicker > > GetEarliestAvailableCronOccurrence ( Guid [ ] ids , CancellationToken cancellationToken = default )
525535 {
526536 var now = _clock . UtcNow ;
537+ < << << << HEAD
527538 var mainSchedulerThreshold = now . AddMilliseconds ( - now . Millisecond ) ;
539+ = == == ==
540+ var mainSchedulerThreshold = now . AddSeconds ( - 1 ) ;
541+ var idList = ids . ToList ( ) ;
542+ > >>> >>> 39 b9b90 ( Fix . NET 9 + EF Core query failures caused by ReadOnlySpan array. Contains ( ) ( #574 ) )
528543 await using var dbContext = await DbContextFactory . CreateDbContextAsync ( cancellationToken ) . ConfigureAwait ( false ) ; ;
529544 return await dbContext . Set < CronTickerOccurrenceEntity < TCronTicker > > ( )
530545 . AsNoTracking ( )
531546 . Include ( x => x . CronTicker )
547+ << < << << HEAD
532548 . Where ( x => ids . Contains ( x . CronTickerId ) )
533549 . Where ( x => x . ExecutionTime >= mainSchedulerThreshold ) // Only recent/upcoming tasks (not heavily overdue)
550+ == = == ==
551+ . Where ( x => idList . Contains ( x . CronTickerId ) )
552+ . Where ( x => x . ExecutionTime >= mainSchedulerThreshold ) // Only items within the 1-second main scheduler window
553+ >>> > >>> 39 b9b90 ( Fix . NET 9 + EF Core query failures caused by ReadOnlySpan array. Contains ( ) ( #574 ) )
534554 . WhereCanAcquire ( _lockHolder )
535555 . OrderBy ( x => x . ExecutionTime )
536556 . Select ( MappingExtensions . ForLatestQueuedCronTickerOccurrence < CronTickerOccurrenceEntity < TCronTicker > , TCronTicker > ( ) )
@@ -554,9 +574,15 @@ public async Task UpdateCronTickerOccurrencesWithUnifiedContext(Guid[] cronOccur
554574 CancellationToken cancellationToken = default )
555575 {
556576 await using var dbContext = await DbContextFactory . CreateDbContextAsync ( cancellationToken ) . ConfigureAwait ( false ) ; ;
577+ var idList = cronOccurrenceIds . ToList ( ) ;
557578 await dbContext . Set < CronTickerOccurrenceEntity < TCronTicker > > ( )
579+ << < << << HEAD
558580 . Where ( x => cronOccurrenceIds . Contains ( x . Id ) )
559581 . ExecuteUpdateAsync ( MappingExtensions . UpdateCronTickerOccurrence < TCronTicker > ( functionContext ) , cancellationToken )
582+ == = == ==
583+ . Where ( x => idList . Contains ( x . Id ) )
584+ . ExecuteUpdateAsync ( setter => setter . UpdateCronTickerOccurrence < TCronTicker > ( functionContext ) , cancellationToken )
585+ >>> > >>> 39 b9b90 ( Fix . NET 9 + EF Core query failures caused by ReadOnlySpan array. Contains ( ) ( #574 ) )
560586 . ConfigureAwait ( false ) ;
561587 }
562588
0 commit comments