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
57
if (isCommit(evt) && !this.opts.excludeCommit) {
58
58
const parsed = await parseCommit(evt)
59
59
for (const write of parsed) {
60
60
-
if (!this.opts.filterCollections || this.opts.filterCollections.includes(write.uri.collection)) {
60
60
+
if (
61
61
+
!this.opts.filterCollections ||
62
62
+
this.opts.filterCollections.includes(write.uri.collection)
63
63
+
) {
61
64
yield write
62
65
}
63
66
}
···
167
170
168
171
type Update = CommitMeta & {
169
172
event: 'update'
173
173
+
record: RepoRecord
174
174
+
cid: CID
170
175
}
171
176
172
177
type Delete = CommitMeta & {
+12
-2
src/firehose/ingester.ts
···
10
10
const firehose = new Firehose({})
11
11
12
12
for await (const evt of firehose.run()) {
13
13
-
if (evt.event === 'create') {
13
13
+
// Watch for write events
14
14
+
if (evt.event === 'create' || evt.event === 'update') {
14
15
const record = evt.record
16
16
+
17
17
+
// If the write is a valid status update
15
18
if (
16
19
evt.collection === 'com.example.status' &&
17
20
Status.isRecord(record) &&
18
21
Status.validateRecord(record).success
19
22
) {
23
23
+
// Store the status in our SQLite
20
24
await this.db
21
25
.insertInto('status')
22
26
.values({
···
25
29
updatedAt: record.updatedAt,
26
30
indexedAt: new Date().toISOString(),
27
31
})
28
28
-
.onConflict((oc) => oc.doNothing())
32
32
+
.onConflict((oc) =>
33
33
+
oc.column('authorDid').doUpdateSet({
34
34
+
status: record.status,
35
35
+
updatedAt: record.updatedAt,
36
36
+
indexedAt: new Date().toISOString(),
37
37
+
})
38
38
+
)
29
39
.execute()
30
40
}
31
41
}