+53
-1
app/firehose_client.rb
+53
-1
app/firehose_client.rb
···
1
require 'skyfall'
2
3
require_relative 'init'
4
require_relative 'models/subscription'
5
6
class FirehoseClient
7
attr_accessor :start_cursor, :service
···
15
16
def start
17
return if @sky
18
19
log "Starting firehose process (YJIT = #{RubyVM::YJIT.enabled? ? 'on' : 'off'})"
20
···
94
Subscription.where(service: @service).update_all(cursor: cursor)
95
end
96
97
def process_message(msg)
98
save_cursor(msg.seq) if msg.seq % 1000 == 0
99
···
108
@replaying = false
109
end
110
111
msg.operations.each do |op|
112
case op.type
113
when :bsky_post
114
-
# ...
115
end
116
end
117
end
···
120
def process_account_event(msg)
121
if msg.status == :deleted
122
# ...
123
end
124
end
125
···
1
require 'skyfall'
2
3
require_relative 'init'
4
+
require_relative 'models/post'
5
require_relative 'models/subscription'
6
+
require_relative 'models/user'
7
8
class FirehoseClient
9
attr_accessor :start_cursor, :service
···
17
18
def start
19
return if @sky
20
+
21
+
@active_users = load_users
22
23
log "Starting firehose process (YJIT = #{RubyVM::YJIT.enabled? ? 'on' : 'off'})"
24
···
98
Subscription.where(service: @service).update_all(cursor: cursor)
99
end
100
101
+
def load_users
102
+
User.active.map { |u| [u.did, u] }.then { |list| Hash[list] }
103
+
end
104
+
105
def process_message(msg)
106
save_cursor(msg.seq) if msg.seq % 1000 == 0
107
···
116
@replaying = false
117
end
118
119
+
@current_user = @active_users[msg.repo]
120
+
121
msg.operations.each do |op|
122
case op.type
123
+
when :bsky_like
124
+
process_like(msg, op)
125
+
when :bsky_repost
126
+
process_repost(msg, op)
127
when :bsky_post
128
+
process_post(msg, op)
129
end
130
end
131
end
···
134
def process_account_event(msg)
135
if msg.status == :deleted
136
# ...
137
+
end
138
+
end
139
+
140
+
def process_like(msg, op)
141
+
return unless @current_user
142
+
143
+
if op.action == :create
144
+
@current_user.likes.import_from_record(op.uri, op.raw_record)
145
+
elsif op.action == :delete
146
+
@current_user.likes.where(rkey: op.rkey).delete_all
147
+
end
148
+
end
149
+
150
+
def process_repost(msg, op)
151
+
return unless @current_user
152
+
153
+
if op.action == :create
154
+
@current_user.reposts.import_from_record(op.uri, op.raw_record)
155
+
elsif op.action == :delete
156
+
@current_user.reposts.where(rkey: op.rkey).delete_all
157
+
end
158
+
end
159
+
160
+
def process_post(msg, op)
161
+
if op.action == :create
162
+
if @current_user
163
+
@current_user.quotes.import_from_record(op.uri, op.raw_record)
164
+
@current_user.pins.import_from_record(op.uri, op.raw_record)
165
+
end
166
+
elsif op.action == :delete
167
+
if @current_user
168
+
@current_user.quotes.where(rkey: op.rkey).delete_all
169
+
@current_user.pins.where(rkey: op.rkey).delete_all
170
+
end
171
+
172
+
if post = Post.find_by_at_uri(op.uri)
173
+
post.destroy
174
+
end
175
end
176
end
177
+4
app/models/user.rb
+4
app/models/user.rb