Retro Bulletin Board Systems on atproto. Web app and TUI. lazy mirror of alyraffauf/atbbs atbbs.xyz
forums python tui atproto bbs
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

tui: parallelize some fetches

+49 -39
+6 -4
tui/screens/activity.py
··· 1 + import asyncio 2 + 1 3 from textual import work 2 4 from textual.app import ComposeResult 3 5 from textual.containers import VerticalScroll ··· 72 74 73 75 client = self.app.http_client 74 76 try: 75 - bbs = await resolve_bbs(client, handle) 76 - rec = await get_record( 77 - client, thread_did, "xyz.atboards.thread", thread_tid 77 + bbs, rec, author = await asyncio.gather( 78 + resolve_bbs(client, handle), 79 + get_record(client, thread_did, "xyz.atboards.thread", thread_tid), 80 + resolve_identity(client, thread_did), 78 81 ) 79 - author = await resolve_identity(client, thread_did) 80 82 thread = Thread( 81 83 uri=rec.uri, 82 84 board_uri=rec.value["board"],
+24 -24
tui/screens/sysop.py
··· 1 + import asyncio 2 + 1 3 from textual import work 2 4 from textual.app import ComposeResult 3 5 from textual.containers import Vertical, VerticalScroll ··· 277 279 client = self.app.http_client 278 280 session = self.app.user_session 279 281 280 - # Fetch ban records 281 - try: 282 - ban_records = await list_pds_records( 283 - client, session["pds_url"], session["did"], lexicon.BAN 284 - ) 282 + # Fetch ban and hide records in parallel 283 + ban_result, hide_result = await asyncio.gather( 284 + list_pds_records(client, session["pds_url"], session["did"], lexicon.BAN), 285 + list_pds_records(client, session["pds_url"], session["did"], lexicon.HIDE), 286 + return_exceptions=True, 287 + ) 288 + 289 + if isinstance(ban_result, BaseException): 290 + self._ban_rkeys = {} 291 + else: 285 292 self._ban_rkeys = { 286 293 r["value"]["did"]: AtUri.parse(r["uri"]).rkey 287 - for r in ban_records 294 + for r in ban_result 288 295 if r.get("value", {}).get("did") 289 296 } 290 - except Exception: 291 - self._ban_rkeys = {} 297 + 298 + if isinstance(hide_result, BaseException): 299 + self._hide_rkeys = {} 300 + else: 301 + self._hide_rkeys = { 302 + r["value"]["uri"]: AtUri.parse(r["uri"]).rkey 303 + for r in hide_result 304 + if r.get("value", {}).get("uri") 305 + } 292 306 293 307 # Resolve banned handles 294 308 banned_dids = list(self._ban_rkeys.keys()) 309 + banned_handles: dict[str, str] = {} 295 310 if banned_dids: 296 311 try: 297 312 authors = await resolve_identities_batch(client, banned_dids) 298 313 banned_handles = {did: authors[did].handle for did in authors} 299 314 except Exception: 300 - banned_handles = {} 301 - else: 302 - banned_handles = {} 315 + pass 303 316 304 317 ban_list = self.query_one("#ban-list", ListView) 305 318 ban_list.clear() 306 319 for did in banned_dids: 307 320 label = banned_handles.get(did, did) 308 321 await ban_list.append(ListItem(Static(f" {label}"), name=f"ban:{did}")) 309 - 310 - # Fetch hide records 311 - try: 312 - hide_records = await list_pds_records( 313 - client, session["pds_url"], session["did"], lexicon.HIDE 314 - ) 315 - self._hide_rkeys = { 316 - r["value"]["uri"]: AtUri.parse(r["uri"]).rkey 317 - for r in hide_records 318 - if r.get("value", {}).get("uri") 319 - } 320 - except Exception: 321 - self._hide_rkeys = {} 322 322 323 323 hide_list = self.query_one("#hide-list", ListView) 324 324 hide_list.clear()
+19 -11
tui/screens/thread.py
··· 1 + import asyncio 1 2 from pathlib import Path 2 3 3 4 from platformdirs import user_downloads_dir ··· 118 119 for r in result.replies: 119 120 self._replies_map[r.uri] = r 120 121 121 - # Fetch any quoted replies not already known 122 + # Fetch any quoted replies not already known (in parallel) 122 123 missing = [ 123 124 r.quote 124 125 for r in result.replies 125 126 if r.quote and r.quote not in self._replies_map 126 127 ] 127 - for uri in missing: 128 - try: 129 - parsed = AtUri.parse(uri) 130 - rec = await get_record( 131 - client, parsed.did, parsed.collection, parsed.rkey 132 - ) 133 - author = await resolve_identity(client, parsed.did) 134 - self._replies_map[uri] = reply_from_record(rec, author) 135 - except Exception: 136 - pass 128 + 129 + async def fetch_quote(uri: str): 130 + parsed = AtUri.parse(uri) 131 + rec, author = await asyncio.gather( 132 + get_record(client, parsed.did, parsed.collection, parsed.rkey), 133 + resolve_identity(client, parsed.did), 134 + ) 135 + return uri, reply_from_record(rec, author) 136 + 137 + if missing: 138 + results = await asyncio.gather( 139 + *[fetch_quote(uri) for uri in missing], 140 + return_exceptions=True, 141 + ) 142 + for r in results: 143 + if isinstance(r, tuple): 144 + self._replies_map[r[0]] = r[1] 137 145 138 146 for r in result.replies: 139 147 quote_text = None