mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-05 19:38:39 +00:00
Remove debug prints and prevent activities from being registered in read only mode
This commit is contained in:
parent
27cbb14a49
commit
180cac5aa9
3 changed files with 20 additions and 37 deletions
|
@ -30,9 +30,6 @@ public class ActivityController : ControllerBase
|
|||
this.database = database;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is only used for LBP2 so we exclude playlists
|
||||
/// </summary>
|
||||
private async Task<IQueryable<ActivityDto>> GetFilters
|
||||
(
|
||||
IQueryable<ActivityDto> dtoQuery,
|
||||
|
@ -123,8 +120,6 @@ public class ActivityController : ControllerBase
|
|||
dto.Activity.Type != EventType.AddLevelToPlaylist);
|
||||
}
|
||||
|
||||
Logger.Debug(predicate.ToString(), LogArea.Activity);
|
||||
|
||||
dtoQuery = dtoQuery.Where(predicate);
|
||||
|
||||
return dtoQuery;
|
||||
|
@ -344,8 +339,6 @@ public class ActivityController : ControllerBase
|
|||
|
||||
List<OuterActivityGroup> outerGroups = groups.ToOuterActivityGroups();
|
||||
|
||||
PrintOuterGroups(outerGroups);
|
||||
|
||||
long oldestTimestamp = GetOldestTime(groups, times.Start).ToUnixTimeMilliseconds();
|
||||
|
||||
await this.CacheEntities(outerGroups);
|
||||
|
|
|
@ -22,13 +22,20 @@ public class ActivityInterceptor : SaveChangesInterceptor
|
|||
public required object OldEntity { get; init; }
|
||||
}
|
||||
|
||||
private readonly ConcurrentDictionary<(Type Type, int HashCode), CustomTrackedEntity> unsavedEntities;
|
||||
private struct TrackedEntityKey
|
||||
{
|
||||
public Type Type { get; set; }
|
||||
public int HashCode { get; set; }
|
||||
public Guid ContextId { get; set; }
|
||||
}
|
||||
|
||||
private readonly ConcurrentDictionary<TrackedEntityKey, CustomTrackedEntity> unsavedEntities;
|
||||
private readonly IEntityEventHandler eventHandler;
|
||||
|
||||
public ActivityInterceptor(IEntityEventHandler eventHandler)
|
||||
{
|
||||
this.eventHandler = eventHandler;
|
||||
this.unsavedEntities = new ConcurrentDictionary<(Type Type, int HashCode), CustomTrackedEntity>();
|
||||
this.unsavedEntities = new ConcurrentDictionary<TrackedEntityKey, CustomTrackedEntity>();
|
||||
}
|
||||
|
||||
#region Hooking stuff
|
||||
|
@ -78,8 +85,12 @@ public class ActivityInterceptor : SaveChangesInterceptor
|
|||
if (entry.Metadata.Name.Contains("Token")) continue;
|
||||
|
||||
if (entry.State is not (EntityState.Added or EntityState.Deleted or EntityState.Modified)) continue;
|
||||
|
||||
this.unsavedEntities.TryAdd((entry.Entity.GetType(), entry.Entity.GetHashCode()),
|
||||
this.unsavedEntities.TryAdd(new TrackedEntityKey
|
||||
{
|
||||
ContextId = context.ContextId.InstanceId,
|
||||
Type = entry.Entity.GetType(),
|
||||
HashCode = entry.Entity.GetHashCode(),
|
||||
},
|
||||
new CustomTrackedEntity
|
||||
{
|
||||
State = entry.State,
|
||||
|
@ -97,7 +108,7 @@ public class ActivityInterceptor : SaveChangesInterceptor
|
|||
|
||||
List<EntityEntry> entries = context.ChangeTracker.Entries().ToList();
|
||||
|
||||
foreach (KeyValuePair<(Type Type, int HashCode), CustomTrackedEntity> kvp in this.unsavedEntities)
|
||||
foreach (KeyValuePair<TrackedEntityKey, CustomTrackedEntity> kvp in this.unsavedEntities)
|
||||
{
|
||||
EntityEntry entry = entries.FirstOrDefault(e =>
|
||||
e.Metadata.ClrType == kvp.Key.Type && e.Entity.GetHashCode() == kvp.Key.HashCode);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
|
@ -13,10 +14,6 @@ using LBPUnion.ProjectLighthouse.Types.Entities.Website;
|
|||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
#if DEBUG
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
#endif
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Types.Activity;
|
||||
|
||||
|
@ -24,7 +21,6 @@ public class ActivityEntityEventHandler : IEntityEventHandler
|
|||
{
|
||||
public void OnEntityInserted<T>(DatabaseContext database, T entity) where T : class
|
||||
{
|
||||
Logger.Debug($@"OnEntityInserted: {entity.GetType().Name}", LogArea.Activity);
|
||||
ActivityEntity? activity = entity switch
|
||||
{
|
||||
SlotEntity slot => slot.Type switch
|
||||
|
@ -50,7 +46,7 @@ public class ActivityEntityEventHandler : IEntityEventHandler
|
|||
},
|
||||
_ => null,
|
||||
},
|
||||
CommentType.Profile => new UserCommentActivityEntity()
|
||||
CommentType.Profile => new UserCommentActivityEntity
|
||||
{
|
||||
Type = EventType.CommentOnUser,
|
||||
CommentId = comment.CommentId,
|
||||
|
@ -199,6 +195,8 @@ public class ActivityEntityEventHandler : IEntityEventHandler
|
|||
{
|
||||
if (activity == null) return;
|
||||
|
||||
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode) return;
|
||||
|
||||
Logger.Debug("Inserting activity: " + activity.GetType().Name, LogArea.Activity);
|
||||
|
||||
RemoveDuplicateEvents(database, activity);
|
||||
|
@ -210,24 +208,6 @@ public class ActivityEntityEventHandler : IEntityEventHandler
|
|||
|
||||
public void OnEntityChanged<T>(DatabaseContext database, T origEntity, T currentEntity) where T : class
|
||||
{
|
||||
#if DEBUG
|
||||
foreach (PropertyInfo propInfo in currentEntity.GetType().GetProperties())
|
||||
{
|
||||
if (!propInfo.CanRead || !propInfo.CanWrite) continue;
|
||||
|
||||
if (propInfo.CustomAttributes.Any(c => c.AttributeType == typeof(NotMappedAttribute))) continue;
|
||||
|
||||
object? origVal = propInfo.GetValue(origEntity);
|
||||
object? newVal = propInfo.GetValue(currentEntity);
|
||||
if ((origVal == null && newVal == null) || (origVal != null && newVal != null && origVal.Equals(newVal))) continue;
|
||||
|
||||
Logger.Debug($@"Value for {propInfo.Name} changed", LogArea.Activity);
|
||||
Logger.Debug($@"Orig val: {origVal?.ToString() ?? "null"}", LogArea.Activity);
|
||||
Logger.Debug($@"New val: {newVal?.ToString() ?? "null"}", LogArea.Activity);
|
||||
}
|
||||
Logger.Debug($@"OnEntityChanged: {currentEntity.GetType().Name}", LogArea.Activity);
|
||||
#endif
|
||||
|
||||
ActivityEntity? activity = null;
|
||||
switch (currentEntity)
|
||||
{
|
||||
|
@ -354,7 +334,6 @@ public class ActivityEntityEventHandler : IEntityEventHandler
|
|||
|
||||
public void OnEntityDeleted<T>(DatabaseContext database, T entity) where T : class
|
||||
{
|
||||
Logger.Debug($@"OnEntityDeleted: {entity.GetType().Name}", LogArea.Activity);
|
||||
ActivityEntity? activity = entity switch
|
||||
{
|
||||
HeartedLevelEntity heartedLevel => heartedLevel.Slot.Type switch
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue