mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-04-09 04:18:17 +02:00
refactor db dvms
This commit is contained in:
parent
59b0e143e6
commit
81de3a4cd2
@ -27,6 +27,8 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
FIX_COST: float = 0
|
||||
dvm_config: DVMConfig
|
||||
last_schedule: int
|
||||
db_since = 3600
|
||||
db_name = "db/nostr_recent_notes.db"
|
||||
|
||||
def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
||||
admin_config: AdminConfig = None, options=None):
|
||||
@ -87,7 +89,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
|
||||
database = NostrDatabase.sqlite("db/nostr_recent_notes.db")
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
||||
|
||||
cli.add_relay("wss://relay.damus.io")
|
||||
@ -95,7 +97,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
|
||||
# Negentropy reconciliation
|
||||
# Query events from database
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - 3600
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
||||
|
||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(lasthour)
|
||||
@ -142,13 +144,13 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
database = NostrDatabase.sqlite("db/nostr_recent_notes.db")
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
cli.add_relay("wss://relay.damus.io")
|
||||
cli.connect()
|
||||
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - 3600
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
||||
|
||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION, definitions.EventDefinitions.KIND_ZAP]).since(lasthour) # Notes, reactions, zaps
|
||||
@ -158,7 +160,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
cli.reconcile(filter1, dbopts)
|
||||
database.delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - 3600))) # Clear old events so db doesnt get too full.
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesnt get too full.
|
||||
|
||||
print("Done Syncing Notes of Last hour.")
|
||||
|
||||
|
@ -28,6 +28,8 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
FIX_COST: float = 0
|
||||
dvm_config: DVMConfig
|
||||
last_schedule: int
|
||||
db_since = 2 * 3600
|
||||
db_name = "db/nostr_recent_notes2.db"
|
||||
|
||||
def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
||||
admin_config: AdminConfig = None, options=None):
|
||||
@ -94,7 +96,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
|
||||
database = NostrDatabase.sqlite("db/nostr_recent_notes2.db")
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
||||
cli.add_relay("wss://relay.damus.io")
|
||||
cli.add_relay("wss://nos.lol")
|
||||
@ -112,7 +114,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
|
||||
# Negentropy reconciliation
|
||||
# Query events from database
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - 7200
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
||||
|
||||
|
||||
@ -182,13 +184,13 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
database = NostrDatabase.sqlite("db/nostr_recent_notes2.db")
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
cli.add_relay("wss://relay.damus.io")
|
||||
cli.connect()
|
||||
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - 7200
|
||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
||||
|
||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
|
||||
@ -199,7 +201,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
cli.reconcile(filter1, dbopts)
|
||||
database.delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - 7200))) # Clear old events so db doesnt get too full.
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesnt get too full.
|
||||
|
||||
print("Done Syncing Notes of Last hour.")
|
||||
|
||||
|
@ -26,6 +26,7 @@ class SearchUser(DVMTaskInterface):
|
||||
FIX_COST: float = 0
|
||||
dvm_config: DVMConfig
|
||||
last_schedule: int = 0
|
||||
db_name = "db/nostr_profiles.db"
|
||||
|
||||
def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
||||
admin_config: AdminConfig = None, options=None):
|
||||
@ -84,7 +85,7 @@ class SearchUser(DVMTaskInterface):
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
|
||||
database = NostrDatabase.sqlite("db/nostr_profiles.db")
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
||||
|
||||
cli.add_relay("wss://relay.damus.io")
|
||||
@ -147,7 +148,7 @@ class SearchUser(DVMTaskInterface):
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
database = NostrDatabase.sqlite("db/nostr_profiles.db")
|
||||
database = NostrDatabase.sqlite(self.db_name)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
cli.add_relay("wss://relay.damus.io")
|
||||
|
Loading…
x
Reference in New Issue
Block a user