Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Additional Memory Pressure Enhancements (#590)

Joseph Milazzoc44ef6b04d34
diff --git a/API.Tests/Parser/ComicParserTests.cs b/API.Tests/Parser/ComicParserTests.cs
index c0de4755a..0267a2ceb 100644
--- a/API.Tests/Parser/ComicParserTests.cs
+++ b/API.Tests/Parser/ComicParserTests.cs
@@ -28,6 +28,7 @@ namespace API.Tests.Parser
[InlineData("Invincible 033.5 - Marvel Team-Up 14 (2006) (digital) (Minutemen-Slayer)", "Invincible")]
[InlineData("Batman Wayne Family Adventures - Ep. 001 - Moving In", "Batman Wayne Family Adventures")]
[InlineData("Saga 001 (2012) (Digital) (Empire-Zone).cbr", "Saga")]
+ [InlineData("Batman Beyond 04 (of 6) (1999)", "Batman Beyond")]
public void ParseComicSeriesTest(string filename, string expected)
{
Assert.Equal(expected, API.Parser.Parser.ParseComicSeries(filename));
@@ -76,6 +77,7 @@ namespace API.Tests.Parser
[InlineData("Invincible 033.5 - Marvel Team-Up 14 (2006) (digital) (Minutemen-Slayer)", "33.5")]
[InlineData("Batman Wayne Family Adventures - Ep. 014 - Moving In", "14")]
[InlineData("Saga 001 (2012) (Digital) (Empire-Zone)", "1")]
+ [InlineData("Batman Beyond 04 (of 6) (1999)", "4")]
public void ParseComicChapterTest(string filename, string expected)
{
Assert.Equal(expected, API.Parser.Parser.ParseComicChapter(filename));
diff --git a/API/Parser/Parser.cs b/API/Parser/Parser.cs
index 0c8f69744..3a06d6684 100644
--- a/API/Parser/Parser.cs
+++ b/API/Parser/Parser.cs
@@ -371,11 +371,16 @@ namespace API.Parser
private static readonly Regex[] ComicChapterRegex = new[]
{
- // Batman & Wildcat (1 of 3)
+ // Batman & Wildcat (1 of 3)
new Regex(
@"(?<Series>.*(\d{4})?)( |_)(?:\((?<Chapter>\d+) of \d+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled,
RegexTimeout),
+ // Batman Beyond 04 (of 6) (1999)
+ new Regex(
+ @"(?<Series>.+?)(?<Chapter>\d+)(\s|_|-)?\(of",
+ RegexOptions.IgnoreCase | RegexOptions.Compiled,
+ RegexTimeout),
// Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)
new Regex(
@"^(?<Series>.*)(?: |_)v(?<Volume>\d+)(?: |_)(c? ?)(?<Chapter>(\d+(\.\d)?)-?(\d+(\.\d)?)?)(c? ?)",
diff --git a/API/Services/ArchiveService.cs b/API/Services/ArchiveService.cs
index 2c22b18e7..bfa36595c 100644
--- a/API/Services/ArchiveService.cs
+++ b/API/Services/ArchiveService.cs
@@ -28,7 +28,6 @@ namespace API.Services
{
private readonly ILogger<ArchiveService> _logger;
private readonly IDirectoryService _directoryService;
- private static readonly RecyclableMemoryStreamManager StreamManager = new();
private readonly NaturalSortComparer _comparer;
private const string ComicInfoFilename = "comicinfo";
@@ -169,7 +168,7 @@ namespace API.Services
var entry = archive.Entries.Single(e => e.FullName == entryName);
using var stream = entry.Open();
- return CreateThumbnail(entry.FullName, stream, fileName);
+ return CreateThumbnail(archivePath + " - " + entry.FullName, stream, fileName);
}
case ArchiveLibrary.SharpCompress:
{
@@ -180,18 +179,16 @@ namespace API.Services
var entryName = FindFolderEntry(entryNames) ?? FirstFileEntry(entryNames);
var entry = archive.Entries.Single(e => e.Key == entryName);
- using var ms = StreamManager.GetStream();
- entry.WriteTo(ms);
- ms.Position = 0;
+ using var stream = entry.OpenEntryStream();
- return CreateThumbnail(entry.Key, ms, fileName); // Path.GetExtension(entry.Key)
+ return CreateThumbnail(archivePath + " - " + entry.Key, stream, fileName);
}
case ArchiveLibrary.NotSupported:
_logger.LogWarning("[GetCoverImage] This archive cannot be read: {ArchivePath}. Defaulting to no cover image", archivePath);
- return String.Empty;
+ return string.Empty;
default:
_logger.LogWarning("[GetCoverImage] There was an exception when reading archive stream: {ArchivePath}. Defaulting to no cover image", archivePath);
- return String.Empty;
+ return string.Empty;
}
}
catch (Exception ex)
@@ -199,7 +196,7 @@ namespace API.Services
_logger.LogWarning(ex, "[GetCoverImage] There was an exception when reading archive stream: {ArchivePath}. Defaulting to no cover image", archivePath);
}
- return String.Empty;
+ return string.Empty;
}
/// <summary>
@@ -292,9 +289,7 @@ namespace API.Services
&& !Parser.Parser.HasBlacklistedFolderInPath(entry.Key)
&& Parser.Parser.IsXml(entry.Key))
{
- using var ms = StreamManager.GetStream();
- entry.WriteTo(ms);
- ms.Position = 0;
+ using var ms = entry.OpenEntryStream();
var serializer = new XmlSerializer(typeof(ComicInfo));
var info = (ComicInfo) serializer.Deserialize(ms);
diff --git a/API/Services/BookService.cs b/API/Services/BookService.cs
index ff4830e55..6231de20a 100644
--- a/API/Services/BookService.cs
+++ b/API/Services/BookService.cs
@@ -4,6 +4,7 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
+using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
@@ -378,7 +379,9 @@ namespace API.Services
for (var pageNumber = 0; pageNumber < pages; pageNumber++)
{
GetPdfPage(docReader, pageNumber, stream);
- File.WriteAllBytes(Path.Combine(targetDirectory, "Page-" + pageNumber + ".png"), stream.ToArray());
+ using var fileStream = File.Create(Path.Combine(targetDirectory, "Page-" + pageNumber + ".png"));
+ stream.Seek(0, SeekOrigin.Begin);
+ stream.CopyTo(fileStream);
}
}