Skip to content

Commit

Permalink
Critical Progress Order Fix (#2477)
Browse files Browse the repository at this point in the history
  • Loading branch information
majora2007 authored Dec 5, 2023
1 parent 36aa5c5 commit 980a123
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions API/Data/Repositories/AppUserProgressRepository.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using API.Data.ManualMigrations;
using API.DTOs;
Expand Down Expand Up @@ -218,15 +219,16 @@ public async Task UpdateAllProgressThatAreMoreThanChapterPages()
})
.AsEnumerable();

// Need to run this Raw because DataContext will update LastModified on the entity which breaks ordering for progress
var sqlBuilder = new StringBuilder();
foreach (var update in updates)
{
_context.AppUserProgresses
.Where(p => p.Id == update.ProgressId)
.ToList() // Execute the query to ensure exclusive lock
.ForEach(p => p.PagesRead = update.NewPagesRead);
sqlBuilder.Append($"UPDATE AppUserProgresses SET PagesRead = {update.NewPagesRead} WHERE Id = {update.ProgressId};");
}

await _context.SaveChangesAsync();
// Execute the batch SQL
var batchSql = sqlBuilder.ToString();
await _context.Database.ExecuteSqlRawAsync(batchSql);
}

#nullable enable
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "GPL-3.0",
"url": "https://github.com/Kareadita/Kavita/blob/develop/LICENSE"
},
"version": "0.7.10.20"
"version": "0.7.11.0"
},
"servers": [
{
Expand Down

0 comments on commit 980a123

Please sign in to comment.