refactor: cleanup import
This commit is contained in:
parent
e6e12a91fe
commit
17df7e73d1
@ -42,13 +42,16 @@ public class ImportController : Controller
|
||||
var ev = JsonConvert.DeserializeObject<NostrEvent>(line, NostrSerializer.Settings);
|
||||
if (ev != default && ev.IsSignatureValid())
|
||||
{
|
||||
if (ev.Kind is NostrKind.Metadata)
|
||||
if (RelayListener.AcceptedKinds.Contains(ev.Kind))
|
||||
{
|
||||
await _redisStore.StoreProfile(CompactProfile.FromNostrEvent(ev)!);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _redisStore.StoreEvent(CompactEvent.FromNostrEvent(ev));
|
||||
if (ev.Kind is NostrKind.Metadata)
|
||||
{
|
||||
await _redisStore.StoreProfile(CompactProfile.FromNostrEvent(ev)!);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _redisStore.StoreEvent(CompactEvent.FromNostrEvent(ev));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ public class OpenGraphController : Controller
|
||||
|
||||
break;
|
||||
}
|
||||
case 1_313:
|
||||
case 1_313: // stream clip
|
||||
{
|
||||
var stream = ev.GetFirstTagValue("r")!;
|
||||
ret.AddRange(new KeyValuePair<string, string>[]
|
||||
|
@ -21,7 +21,7 @@ public class RedisEventCache : IEventHandler
|
||||
await _redisStore.StoreProfile(p);
|
||||
}
|
||||
}
|
||||
else if (ev.Kind is NostrKind.ShortTextNote or NostrKind.LongFormContent or NostrKind.LiveEvent or NostrKind.LiveChatMessage)
|
||||
else
|
||||
{
|
||||
await _redisStore.StoreEvent(CompactEvent.FromNostrEvent(ev));
|
||||
}
|
||||
|
@ -10,6 +10,19 @@ namespace NostrServices.Services;
|
||||
|
||||
public class RelayListener : IHostedService
|
||||
{
|
||||
public static readonly NostrKind[] AcceptedKinds =
|
||||
[
|
||||
NostrKind.Metadata,
|
||||
NostrKind.ShortTextNote,
|
||||
NostrKind.Zap,
|
||||
NostrKind.GenericRepost,
|
||||
NostrKind.LiveEvent,
|
||||
NostrKind.LiveChatMessage,
|
||||
(NostrKind)1_313, // stream clip
|
||||
NostrKind.LongFormContent,
|
||||
NostrKind.ClassifiedListing
|
||||
];
|
||||
|
||||
private readonly NostrListener _nostr;
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
@ -38,18 +51,7 @@ public class RelayListener : IHostedService
|
||||
|
||||
_nostr.RegisterFilter(subId, new NostrFilter()
|
||||
{
|
||||
Kinds = new[]
|
||||
{
|
||||
NostrKind.Metadata,
|
||||
NostrKind.Reaction,
|
||||
NostrKind.Zap,
|
||||
NostrKind.EncryptedDm,
|
||||
NostrKind.GenericRepost,
|
||||
NostrKind.LiveEvent,
|
||||
NostrKind.LiveChatMessage,
|
||||
NostrKind.ShortTextNote,
|
||||
NostrKind.LongFormContent
|
||||
},
|
||||
Kinds = AcceptedKinds,
|
||||
Limit = 0
|
||||
});
|
||||
|
||||
@ -71,7 +73,8 @@ public class RelayListener : IHostedService
|
||||
try
|
||||
{
|
||||
var msg = await _queue.ReceiveAsync();
|
||||
if (Math.Abs((DateTime.UtcNow - msg.CreatedAt!.Value).TotalMinutes) > 10)
|
||||
const int eventWindowMinutes = 10;
|
||||
if (Math.Abs((DateTime.UtcNow - msg.CreatedAt!.Value).TotalMinutes) > eventWindowMinutes)
|
||||
{
|
||||
// skip events older/newer than 10mins from now
|
||||
continue;
|
||||
@ -82,7 +85,7 @@ public class RelayListener : IHostedService
|
||||
if (hasSeen != default) continue;
|
||||
|
||||
_logger.LogDebug(JsonConvert.SerializeObject(msg, NostrSerializer.Settings));
|
||||
_cache.Set(seenKey, true, TimeSpan.FromMinutes(10));
|
||||
_cache.Set(seenKey, true, TimeSpan.FromMinutes(eventWindowMinutes));
|
||||
|
||||
foreach (var eventHandler in _handlers)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user