1
1
import { CID } from 'multiformats/cid'
2
- import { TID } from '@atproto/common'
2
+ import { dataToCborBlock , TID } from '@atproto/common'
3
3
import * as crypto from '@atproto/crypto'
4
+ import { lexToIpld } from '@atproto/lexicon'
4
5
import {
5
6
Commit ,
6
7
CommitData ,
@@ -69,6 +70,7 @@ export class Repo extends ReadableRepo {
69
70
since : null ,
70
71
prev : null ,
71
72
newBlocks,
73
+ relevantBlocks : newBlocks ,
72
74
removedCids : diff . removedCids ,
73
75
}
74
76
}
@@ -140,11 +142,22 @@ export class Repo extends ReadableRepo {
140
142
const newBlocks = diff . newMstBlocks
141
143
const removedCids = diff . removedCids
142
144
145
+ const relevantBlocks = new BlockMap ( )
146
+ await Promise . all (
147
+ writes . map ( ( op ) =>
148
+ data . addBlocksForPath (
149
+ util . formatDataKey ( op . collection , op . rkey ) ,
150
+ relevantBlocks ,
151
+ ) ,
152
+ ) ,
153
+ )
154
+
143
155
const addedLeaves = leaves . getMany ( diff . newLeafCids . toList ( ) )
144
156
if ( addedLeaves . missing . length > 0 ) {
145
157
throw new Error ( `Missing leaf blocks: ${ addedLeaves . missing } ` )
146
158
}
147
159
newBlocks . addMap ( addedLeaves . blocks )
160
+ relevantBlocks . addMap ( addedLeaves . blocks )
148
161
149
162
const rev = TID . nextStr ( this . commit . rev )
150
163
const commit = await util . signCommit (
@@ -157,21 +170,20 @@ export class Repo extends ReadableRepo {
157
170
} ,
158
171
keypair ,
159
172
)
160
- const commitCid = await newBlocks . add ( commit )
161
-
162
- // ensure the commit cid actually changed
163
- if ( commitCid . equals ( this . cid ) ) {
164
- newBlocks . delete ( commitCid )
165
- } else {
173
+ const commitBlock = await dataToCborBlock ( lexToIpld ( commit ) )
174
+ if ( ! commitBlock . cid . equals ( this . cid ) ) {
175
+ newBlocks . set ( commitBlock . cid , commitBlock . bytes )
176
+ relevantBlocks . set ( commitBlock . cid , commitBlock . bytes )
166
177
removedCids . add ( this . cid )
167
178
}
168
179
169
180
return {
170
- cid : commitCid ,
181
+ cid : commitBlock . cid ,
171
182
rev,
172
183
since : this . commit . rev ,
173
184
prev : this . cid ,
174
185
newBlocks,
186
+ relevantBlocks,
175
187
removedCids,
176
188
}
177
189
}
@@ -208,6 +220,7 @@ export class Repo extends ReadableRepo {
208
220
since : null ,
209
221
prev : null ,
210
222
newBlocks,
223
+ relevantBlocks : newBlocks ,
211
224
removedCids : new CidSet ( [ this . cid ] ) ,
212
225
}
213
226
}
0 commit comments