Class: Tempest::HandleResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/tempest/handle_resolver.rb

Overview

Resolves AT Protocol DIDs to Bluesky handles via app.bsky.actor.getProfile. Caches both positive and negative lookups in-process so a busy Jetstream feed doesn’t hammer the PDS on every event.

Constant Summary collapse

NOT_FOUND =
Object.new.freeze

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ HandleResolver

Returns a new instance of HandleResolver.



10
11
12
13
14
# File 'lib/tempest/handle_resolver.rb', line 10

def initialize(client:)
  @client = client
  @cache = {}
  @mutex = Mutex.new
end

Instance Method Details

#resolve(did) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/tempest/handle_resolver.rb', line 16

def resolve(did)
  cached = @mutex.synchronize { @cache[did] }
  return cached_value(cached) unless cached.nil?

  handle = lookup(did)
  @mutex.synchronize { @cache[did] = handle.nil? ? NOT_FOUND : handle }
  handle
end

#seed(did, handle) ⇒ Object



25
26
27
# File 'lib/tempest/handle_resolver.rb', line 25

def seed(did, handle)
  @mutex.synchronize { @cache[did] = handle }
end