Don't log exceptions to Sentry when debugging locally. Fixed a constraint issue with collection tags that prevented deleting series. Ensure when we scan we add SeriesMetadata objects to existing series. (#265)

This commit is contained in:
Joseph Milazzo 2021-06-04 17:49:19 -05:00 committed by GitHub
parent 606e4c8b12
commit aa7439178c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 51 deletions

View File

@ -172,10 +172,11 @@ namespace API.Controllers
var username = User.GetUsername(); var username = User.GetUsername();
_logger.LogInformation("Library {LibraryId} is being deleted by {UserName}", libraryId, username); _logger.LogInformation("Library {LibraryId} is being deleted by {UserName}", libraryId, username);
var series = await _unitOfWork.SeriesRepository.GetSeriesForLibraryIdAsync(libraryId); var series = await _unitOfWork.SeriesRepository.GetSeriesForLibraryIdAsync(libraryId);
var seriesIds = series.Select(x => x.Id).ToArray();
var chapterIds = var chapterIds =
await _unitOfWork.SeriesRepository.GetChapterIdsForSeriesAsync(series.Select(x => x.Id).ToArray()); await _unitOfWork.SeriesRepository.GetChapterIdsForSeriesAsync(seriesIds);
var result = await _unitOfWork.LibraryRepository.DeleteLibrary(libraryId);
var result = await _unitOfWork.LibraryRepository.DeleteLibrary(libraryId);
if (result && chapterIds.Any()) if (result && chapterIds.Any())
{ {
_taskScheduler.CleanupChapters(chapterIds); _taskScheduler.CleanupChapters(chapterIds);

View File

@ -65,7 +65,7 @@ namespace API.Data.Migrations
column: x => x.SeriesMetadatasId, column: x => x.SeriesMetadatasId,
principalTable: "SeriesMetadata", principalTable: "SeriesMetadata",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.NoAction); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(

View File

@ -148,9 +148,6 @@ namespace API.Data.Migrations
b.Property<bool>("BookReaderTapToPaginate") b.Property<bool>("BookReaderTapToPaginate")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("BookReaderReadingDirection")
.HasColumnType("INTEGER");
b.Property<int>("PageSplitOption") b.Property<int>("PageSplitOption")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");

View File

@ -85,51 +85,55 @@ namespace API
}); });
}); });
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
webBuilder.UseSentry(options => if (environment != Environments.Development)
{ {
options.Dsn = "https://40f4e7b49c094172a6f99d61efb2740f@o641015.ingest.sentry.io/5757423"; webBuilder.UseSentry(options =>
options.MaxBreadcrumbs = 200;
options.AttachStacktrace = true;
options.Debug = false;
options.SendDefaultPii = false;
options.DiagnosticLevel = SentryLevel.Debug;
options.ShutdownTimeout = TimeSpan.FromSeconds(5);
options.Release = BuildInfo.Version.ToString();
options.AddExceptionFilterForType<OutOfMemoryException>();
options.AddExceptionFilterForType<NetVips.VipsException>();
options.AddExceptionFilterForType<InvalidDataException>();
options.AddExceptionFilterForType<KavitaException>();
options.BeforeSend = sentryEvent =>
{ {
if (sentryEvent.Exception != null options.Dsn = "https://40f4e7b49c094172a6f99d61efb2740f@o641015.ingest.sentry.io/5757423";
&& sentryEvent.Exception.Message.Contains("[GetCoverImage] This archive cannot be read:") options.MaxBreadcrumbs = 200;
&& sentryEvent.Exception.Message.Contains("[BookService] ")) options.AttachStacktrace = true;
{ options.Debug = false;
return null; // Don't send this event to Sentry options.SendDefaultPii = false;
} options.DiagnosticLevel = SentryLevel.Debug;
options.ShutdownTimeout = TimeSpan.FromSeconds(5);
options.Release = BuildInfo.Version.ToString();
options.AddExceptionFilterForType<OutOfMemoryException>();
options.AddExceptionFilterForType<NetVips.VipsException>();
options.AddExceptionFilterForType<InvalidDataException>();
options.AddExceptionFilterForType<KavitaException>();
sentryEvent.ServerName = null; // Never send Server Name to Sentry options.BeforeSend = sentryEvent =>
return sentryEvent;
};
options.ConfigureScope(scope =>
{
scope.User = new User()
{ {
Id = HashUtil.AnonymousToken() if (sentryEvent.Exception != null
&& sentryEvent.Exception.Message.Contains("[GetCoverImage] This archive cannot be read:")
&& sentryEvent.Exception.Message.Contains("[BookService] "))
{
return null; // Don't send this event to Sentry
}
sentryEvent.ServerName = null; // Never send Server Name to Sentry
return sentryEvent;
}; };
scope.Contexts.App.Name = BuildInfo.AppName;
scope.Contexts.App.Version = BuildInfo.Version.ToString();
scope.Contexts.App.StartTime = DateTime.UtcNow;
scope.Contexts.App.Hash = HashUtil.AnonymousToken();
scope.Contexts.App.Build = BuildInfo.Release;
scope.SetTag("culture", Thread.CurrentThread.CurrentCulture.Name);
scope.SetTag("branch", BuildInfo.Branch);
});
}); options.ConfigureScope(scope =>
{
scope.User = new User()
{
Id = HashUtil.AnonymousToken()
};
scope.Contexts.App.Name = BuildInfo.AppName;
scope.Contexts.App.Version = BuildInfo.Version.ToString();
scope.Contexts.App.StartTime = DateTime.UtcNow;
scope.Contexts.App.Hash = HashUtil.AnonymousToken();
scope.Contexts.App.Build = BuildInfo.Release;
scope.SetTag("culture", Thread.CurrentThread.CurrentCulture.Name);
scope.SetTag("branch", BuildInfo.Branch);
});
});
}
webBuilder.UseStartup<Startup>(); webBuilder.UseStartup<Startup>();
}); });
} }

View File

@ -228,6 +228,7 @@ namespace API.Services.Tasks
existingSeries.NormalizedName = Parser.Parser.Normalize(existingSeries.Name); existingSeries.NormalizedName = Parser.Parser.Normalize(existingSeries.Name);
existingSeries.OriginalName ??= infos[0].Series; existingSeries.OriginalName ??= infos[0].Series;
existingSeries.Metadata ??= DbFactory.SeriesMetadata(new List<CollectionTag>());
} }
// Now, we only have to deal with series that exist on disk. Let's recalculate the volumes for each series // Now, we only have to deal with series that exist on disk. Let's recalculate the volumes for each series

View File

@ -83,6 +83,7 @@ namespace API
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
app.UseHangfireDashboard(); app.UseHangfireDashboard();
} }
app.UseResponseCompression(); app.UseResponseCompression();
app.UseForwardedHeaders(); app.UseForwardedHeaders();
@ -132,7 +133,7 @@ namespace API
applicationLifetime.ApplicationStopping.Register(OnShutdown); applicationLifetime.ApplicationStopping.Register(OnShutdown);
applicationLifetime.ApplicationStarted.Register(() => applicationLifetime.ApplicationStarted.Register(() =>
{ {
Console.WriteLine("Kavita - v" + BuildInfo.Version); Console.WriteLine($"Kavita - v{BuildInfo.Version}");
}); });
// Any services that should be bootstrapped go here // Any services that should be bootstrapped go here

View File

@ -20,7 +20,7 @@ namespace Kavita.Common.EnvironmentInfo
var config = attributes.OfType<AssemblyConfigurationAttribute>().FirstOrDefault(); var config = attributes.OfType<AssemblyConfigurationAttribute>().FirstOrDefault();
if (config != null) if (config != null)
{ {
Branch = config.Configuration; Branch = config.Configuration; // TODO: This is not helpful, better to have main/develop branch
} }
Release = $"{Version}-{Branch}"; Release = $"{Version}-{Branch}";