From 89a7623255dc479d1599c85f0b8a4c77aabb32bc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 28 May 2023 18:02:05 +0200 Subject: [PATCH] Continued: - added last_instance_fetch timestamp --- blocks_empty.db | Bin 28672 -> 28672 bytes fba.py | 27 ++++++++++++++++++++++++--- fetch_instances.py | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/blocks_empty.db b/blocks_empty.db index b83a45698ec8169a185a20908352c3a3b88b1c85..905adbe85ed60f0f74f974521cd72311ec2764e3 100644 GIT binary patch delta 112 zcmZp8z}WDBae}nqX9flab|7X0Vn!g=ov33h`I$k_dm=AiGXpDk0|Vb&-gn#${B!wT zIX7+=6tLvnypi)fBUei{FT1$BJY%Qo=B?ZoOp-bZIf=z3@tJwWC5d^-sqty4CCM2I No_-;lZ}X}q0RSrNA3y*A delta 89 zcmZp8z}WDBae}nqCk6%vb|7X0Vn!g=nW$qd`H4Z#dm=AiGXpF4Y6iZ!yzjVI^UvjX q<=nVgP{5LN^G43|j1wnlbG10|vWv^hGj{lI?&7v!+WeMRI0*pPyccl* diff --git a/fba.py b/fba.py index 95d692b..f54789c 100644 --- a/fba.py +++ b/fba.py @@ -328,6 +328,25 @@ def update_last_error(domain: str, res: any): # DEBUG: print("DEBUG: EXIT!") +def update_last_instance_fetch(domain: str): + #print("DEBUG: Updating last_instance_fetch for domain:", domain) + try: + cursor.execute("UPDATE instances SET last_instance_fetch = ?, last_updated = ? WHERE domain = ? LIMIT 1", [ + time.time(), + time.time(), + domain + ]) + + if cursor.rowcount == 0: + print("WARNING: Did not update any rows:", domain) + + except BaseException as e: + print(f"ERROR: failed SQL query: domain='{domain}',exception:'{str(e)}'") + sys.exit(255) + + connection.commit() + #print("DEBUG: EXIT!") + def update_last_nodeinfo(domain: str): # DEBUG: print("DEBUG: Updating last_nodeinfo for domain:", domain) try: @@ -399,6 +418,8 @@ def get_peers(domain: str, software: str) -> list: # DEBUG: print(f"DEBUG: Adding peer: '{row['host']}'") peers.append(row["host"]) + update_last_instance_fetch(domain) + # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers elif software == "lemmy": @@ -423,7 +444,7 @@ def get_peers(domain: str, software: str) -> list: except BaseException as e: print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception:'{str(e)}'") - update_last_nodeinfo(domain) + update_last_instance_fetch(domain) # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers @@ -462,7 +483,7 @@ def get_peers(domain: str, software: str) -> list: except BaseException as e: print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception:'{str(e)}'") - update_last_nodeinfo(domain) + update_last_instance_fetch(domain) # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers @@ -498,7 +519,7 @@ def get_peers(domain: str, software: str) -> list: print("WARNING: Some error during get():", domain, e) update_last_error(domain, e) - update_last_nodeinfo(domain) + update_last_instance_fetch(domain) # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers diff --git a/fetch_instances.py b/fetch_instances.py index ceadd47..c5188fd 100644 --- a/fetch_instances.py +++ b/fetch_instances.py @@ -53,7 +53,7 @@ fetch_instances(instance, None, None) # Loop through some instances fba.cursor.execute( - "SELECT domain,origin,software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_nodeinfo IS NULL OR last_nodeinfo < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]] + "SELECT domain,origin,software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]] ) rows = fba.cursor.fetchall() -- 2.39.2