Class: MTProto::Updates::MemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/updates/memory_store.rb

Overview

In-memory update-state store: the default backend behind the state machine's persistence port. A real host swaps in its own object answering the same messages over DURABLE storage — load_state / save_state, channel_pts / set_channel_pts, channel_access / set_channel_access, transaction.

load_state returns { pts:, qts:, date:, seq: } or nil on a cold start. A channel's access_hash is persisted next to its pts because a bot cannot getDialogs — it learns the hash only by seeing the channel — so without it a gap in a channel not seen since the last restart could not be recovered. transaction yields; a host may wrap it — the block runs event delivery plus the pts checkpoint — in one DB transaction, so a crash mid-handler re-delivers the update instead of skipping it.

Instance Method Summary collapse

Constructor Details

#initializeMemoryStore

Returns a new instance of MemoryStore.



18
19
20
21
22
# File 'lib/mtproto/updates/memory_store.rb', line 18

def initialize
  @state = nil
  @channel_pts = {}
  @channel_access = {}
end

Instance Method Details

#channel_access(channel_id) ⇒ Object



40
41
42
# File 'lib/mtproto/updates/memory_store.rb', line 40

def channel_access(channel_id)
  @channel_access[channel_id]
end

#channel_pts(channel_id) ⇒ Object



32
33
34
# File 'lib/mtproto/updates/memory_store.rb', line 32

def channel_pts(channel_id)
  @channel_pts[channel_id]
end

#load_stateObject



24
25
26
# File 'lib/mtproto/updates/memory_store.rb', line 24

def load_state
  @state&.dup
end

#save_state(pts:, qts:, date:, seq:) ⇒ Object



28
29
30
# File 'lib/mtproto/updates/memory_store.rb', line 28

def save_state(pts:, qts:, date:, seq:)
  @state = { pts: pts, qts: qts, date: date, seq: seq }
end

#set_channel_access(channel_id, access_hash) ⇒ Object



44
45
46
# File 'lib/mtproto/updates/memory_store.rb', line 44

def set_channel_access(channel_id, access_hash)
  @channel_access[channel_id] = access_hash
end

#set_channel_pts(channel_id, pts) ⇒ Object



36
37
38
# File 'lib/mtproto/updates/memory_store.rb', line 36

def set_channel_pts(channel_id, pts)
  @channel_pts[channel_id] = pts
end

#transactionObject



48
49
50
# File 'lib/mtproto/updates/memory_store.rb', line 48

def transaction
  yield
end