Looks like we finally have a solution.
Change logging to just log a message, instead of the exception. Moved logic to Syncer involvement. When posting the data, if a 500 is returned, then it is up to the Syncer to re-submit it.
This commit is contained in:
parent
73955353cb
commit
004c490dd8
23 changed files with 529 additions and 177 deletions
|
|
@ -65,6 +65,17 @@ public class DataContext : DbContext
|
|||
.OrderByDescending(cl => cl.ChangeTime)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
}
|
||||
|
||||
public async Task CleanupChangeLogAsync(CancellationToken ct = default)
|
||||
{
|
||||
var logs = await ChangeLogs.ToListAsync(ct);
|
||||
if (logs.Count < 50) return;
|
||||
for (var i = 0; i < (logs.Count - 50); i++)
|
||||
{
|
||||
ChangeLogs.Remove(logs[i]);
|
||||
}
|
||||
await base.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public DbSet<History> Histories { get; set; }
|
||||
public DbSet<Playlist> Playlists { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace FreeTubeSync.Database;
|
||||
|
||||
public static class MapData
|
||||
{
|
||||
public static void MapFrom(this object obj2, object obj1)
|
||||
{
|
||||
var props = new Dictionary<string, object?>();
|
||||
var t1Type = obj1.GetType();
|
||||
var t2Type = obj2.GetType();
|
||||
|
||||
var properties = t1Type.GetProperties();
|
||||
foreach (var property in properties)
|
||||
{
|
||||
props[property.Name] = property.GetValue(obj1);
|
||||
}
|
||||
properties = t2Type.GetProperties();
|
||||
foreach (var property in properties)
|
||||
{
|
||||
if (props.ContainsKey(property.Name))
|
||||
{
|
||||
var value = props[property.Name];
|
||||
if (value is string || value is not IEnumerable)
|
||||
property.SetValue(obj2, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapTo<T1, T2>(this IEnumerable<T1> obj1, IList<T2> obj2)
|
||||
where T1 : class where T2 : class, new()
|
||||
{
|
||||
foreach (var obj in obj1)
|
||||
{
|
||||
var newObj = new T2();
|
||||
newObj.MapFrom(obj);
|
||||
obj2.Add(newObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue