tangled
alpha
login
or
join now
graham.systems
/
statusphere-react
forked from
samuel.fm/statusphere-react
0
fork
atom
the statusphere demo reworked into a vite/react app in a monorepo
0
fork
atom
overview
issues
pulls
pipelines
Fix: handle firehose update events
Paul Frazee
2 years ago
087d9ca0
e8d1a842
+18
-3
2 changed files
expand all
collapse all
unified
split
src
firehose
firehose.ts
ingester.ts
+6
-1
src/firehose/firehose.ts
···
57
if (isCommit(evt) && !this.opts.excludeCommit) {
58
const parsed = await parseCommit(evt)
59
for (const write of parsed) {
60
-
if (!this.opts.filterCollections || this.opts.filterCollections.includes(write.uri.collection)) {
0
0
0
61
yield write
62
}
63
}
···
167
168
type Update = CommitMeta & {
169
event: 'update'
0
0
170
}
171
172
type Delete = CommitMeta & {
···
57
if (isCommit(evt) && !this.opts.excludeCommit) {
58
const parsed = await parseCommit(evt)
59
for (const write of parsed) {
60
+
if (
61
+
!this.opts.filterCollections ||
62
+
this.opts.filterCollections.includes(write.uri.collection)
63
+
) {
64
yield write
65
}
66
}
···
170
171
type Update = CommitMeta & {
172
event: 'update'
173
+
record: RepoRecord
174
+
cid: CID
175
}
176
177
type Delete = CommitMeta & {
+12
-2
src/firehose/ingester.ts
···
10
const firehose = new Firehose({})
11
12
for await (const evt of firehose.run()) {
13
-
if (evt.event === 'create') {
0
14
const record = evt.record
0
0
15
if (
16
evt.collection === 'com.example.status' &&
17
Status.isRecord(record) &&
18
Status.validateRecord(record).success
19
) {
0
20
await this.db
21
.insertInto('status')
22
.values({
···
25
updatedAt: record.updatedAt,
26
indexedAt: new Date().toISOString(),
27
})
28
-
.onConflict((oc) => oc.doNothing())
0
0
0
0
0
0
29
.execute()
30
}
31
}
···
10
const firehose = new Firehose({})
11
12
for await (const evt of firehose.run()) {
13
+
// Watch for write events
14
+
if (evt.event === 'create' || evt.event === 'update') {
15
const record = evt.record
16
+
17
+
// If the write is a valid status update
18
if (
19
evt.collection === 'com.example.status' &&
20
Status.isRecord(record) &&
21
Status.validateRecord(record).success
22
) {
23
+
// Store the status in our SQLite
24
await this.db
25
.insertInto('status')
26
.values({
···
29
updatedAt: record.updatedAt,
30
indexedAt: new Date().toISOString(),
31
})
32
+
.onConflict((oc) =>
33
+
oc.column('authorDid').doUpdateSet({
34
+
status: record.status,
35
+
updatedAt: record.updatedAt,
36
+
indexedAt: new Date().toISOString(),
37
+
})
38
+
)
39
.execute()
40
}
41
}