From c078203c8c501020e4fe2c217d6dfb4dd6fbd584 Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Tue, 11 Jun 2024 00:44:21 +0200 Subject: [PATCH] optimizations top zaps --- ...discovery_currently_popular_by_top_zaps.py | 35 ++++++++++++++++--- tests/discovery.py | 4 +-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py b/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py index 494f526..5932cb7 100644 --- a/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py +++ b/nostr_dvm/tasks/content_discovery_currently_popular_by_top_zaps.py @@ -135,25 +135,50 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface): filt = Filter().kinds([definitions.EventDefinitions.KIND_ZAP]).event(event.id()).since(since) zaps = await database.query([filt]) invoice_amount = 0 - + event_author = event.author().to_hex() if len(zaps) >= self.min_reactions: has_preimage = False + has_amount = False overall_amount = 0 for zap in zaps: - if event.author().to_hex() == zap.author().to_hex(): + if event_author == zap.author().to_hex(): continue #Skip self zaps.. invoice_amount = 0 for tag in zap.tags(): - # print(tag.as_vec()) + if tag.as_vec()[0] == 'bolt11': # print(tag.as_vec()[1]) invoice_amount = parse_amount_from_bolt11_invoice(tag.as_vec()[1]) + + has_amount = True + if has_preimage: + break # print(invoice_amount) if tag.as_vec()[0] == 'preimage': if len(tag.as_vec()) > 1: - if tag.as_vec()[1] != "": - overall_amount += invoice_amount + if tag.as_vec()[1] == "": + continue + elif tag.as_vec()[1] != "": + has_preimage = True # TODO further check preimage + if has_amount: + overall_amount += invoice_amount + break + #elif tag.as_vec()[0] == 'description': + # try: + # event = Event.from_json(tag.as_vec()[1]) + # for tag in event.tags(): + # if tag.as_vec()[0] == "amount": + # invoice_amount = tag.as_vec()[1] + # overall_amount += invoice_amount + + # has_amount = True + # if has_preimage: + # break + + # except: + # pass + if has_preimage: ns.finallist[event.id().to_hex()] = overall_amount diff --git a/tests/discovery.py b/tests/discovery.py index 6f64222..f81690d 100644 --- a/tests/discovery.py +++ b/tests/discovery.py @@ -32,7 +32,7 @@ use_logger = True AVOID_PAID_OUTBOX_RELAY_LIST = ["wss://nostrelay.yeghro.site", "wss://nostr.wine", "wss://filter.nostr.wine" "wss://nostr21.com", "wss://nostr.bitcoiner.social", "wss://nostr.orangepill.dev", "wss://relay.lnpay.me", "wss://relay.snort.social", "wss://relay.minds.com/nostr/v1/ws", - "wss://nostr-pub.semisol.dev", "wss://mostr.pub", "wss://relay.mostr.pub", "wss://minds.com", + "wss://nostr-pub.semisol.dev", "wss://mostr.mostr.pub", "wss://relay.mostr.pub", "wss://minds.com", "wss://yabu.me", "wss://relay.yozora.world", "wss://filter.nostr.wine/?global=all", "wss://eden.nostr.land", "wss://relay.orangepill.ovh", "wss://nostr.jcloud.es", "wss://af.purplerelay.com", "wss://za.purplerelay.com", "wss://relay.nostrich.land", "wss://relay.nostrplebs.com", "wss://relay.nostrich.land", @@ -416,7 +416,7 @@ def playground(): options_top_zapped = { "db_name": "db/nostr_recent_notes.db", - "db_since": 60 * 60 * 8, # 8h since gmt, + "db_since": 60 * 60 * 6, # 8h since gmt, } cost = 0 image = "https://image.nostr.build/c6879f458252641d04d0aa65fd7f1e005a4f7362fd407467306edc2f4acdb113.jpg"