mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-12 09:09:35 -04:00
Updated the tagging code from cohle
- Uses a List<string> as the underlying type which EF Core will serialize as JSON. Since SQLite doesn't have any native JSON features, it gets stored as TEXT - Got rid of the alternate pathway used for selecting an image so it always has a degree of randomness assuming enough images were returned - Simplified some of the existing Regex and removed the non capturing groups as they're cancerous - Added/removed images will be spoilered. - Added a metadata property for images. This is a JSON object that EF Core will serialize/deserialize for you and presently contains the user ID of whoever added the image as well as when it was added. Can be easily extended with no migration needed. Will be null for existing images. - Added a migration process for moving Tags to TagList for fishtank
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
using System.Text;
|
||||
using KfChatDotNetBot.Migrations;
|
||||
using KfChatDotNetBot.Services;
|
||||
using KfChatDotNetBot.Settings;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -49,6 +50,21 @@ namespace KfChatDotNetBot
|
||||
logger.Error("Caught an error when attempting to grab the Redis multiplexer");
|
||||
logger.Error(e);
|
||||
}
|
||||
|
||||
if (await db.Images.AnyAsync())
|
||||
{
|
||||
logger.Info("Checking to see if we need to migrate Tags to TagList");
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
var scope = (await db.Images.Where(i => i.Tags != null).ToListAsync()).Where(i => i.TagList.Count == 0).ToList();
|
||||
foreach (var item in scope)
|
||||
{
|
||||
// Ignoring the null as my query literally filters for != null
|
||||
item.TagList = item.Tags!.Split(" ").ToList();
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
logger.Info($"Migrated tags for image {item.Id}");
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
logger.Info("Handing over to bot now");
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
_ = new ChatBot();
|
||||
|
||||
Reference in New Issue
Block a user