@@ -11,7 +11,20 @@ const pull = require('pull-stream')
11
11
const fromEvent = require ( 'pull-stream-util/from-event' )
12
12
const DeferredPromise = require ( 'p-defer' )
13
13
const sleep = require ( 'util' ) . promisify ( setTimeout )
14
- const { and, type, descending, paginate, toCallback } = require ( '../operators' )
14
+ const {
15
+ and,
16
+ type,
17
+ author,
18
+ key,
19
+ votesFor,
20
+ isPublic,
21
+ isRoot,
22
+ hasRoot,
23
+ startFrom,
24
+ paginate,
25
+ descending,
26
+ toCallback,
27
+ } = require ( '../operators' )
15
28
16
29
const dir = '/tmp/ssb-db2-benchmark'
17
30
const oldLogPath = path . join ( dir , 'flume' , 'log.offset' )
@@ -156,3 +169,83 @@ test('initial indexing', async (t) => {
156
169
157
170
await ended . promise
158
171
} )
172
+
173
+ const KEY1 = '%Xwdpu9gRe8wl4i0ssKyU24oGYKXW75hjE5VCbEB9bmM=.sha25' // root post
174
+ const KEY2 = '%EpzOw6sOBb4RGtofVD43GnfImoiw6NzEEsraHsNXF1g=.sha25' // contact
175
+ const KEY3 = '%55wBq68+p45q7/OuPgL+TC07Ifx8ihEW93u/EZaYv6c=.sha256' // another post
176
+ const AUTHOR1 = '@ZngOKXHjrvG+cy7Gjx5pSFunUqcePfmDQQxoUlHFUdU=.ed2551'
177
+ const AUTHOR2 = '@58u/J9+5bOXeYRDCYQ9cJ7kklghIpQFPBYxlhKq1/qs=.ed2551'
178
+
179
+ const queries = {
180
+ 'key one initial' : [ and ( key ( KEY1 ) ) ] ,
181
+
182
+ 'key two' : [ and ( key ( KEY2 ) ) ] ,
183
+
184
+ 'key one again' : [ and ( key ( KEY1 ) ) ] ,
185
+
186
+ 'latest root posts' : [
187
+ and ( type ( 'post' ) , isRoot ( ) , isPublic ( ) ) ,
188
+ startFrom ( 0 ) ,
189
+ paginate ( 25 ) ,
190
+ descending ( ) ,
191
+ ] ,
192
+
193
+ 'latest posts' : [
194
+ and ( type ( 'post' ) , isPublic ( ) ) ,
195
+ startFrom ( 0 ) ,
196
+ paginate ( 25 ) ,
197
+ descending ( ) ,
198
+ ] ,
199
+
200
+ 'votes one initial' : [ and ( votesFor ( KEY1 ) ) ] ,
201
+
202
+ 'votes again' : [ and ( votesFor ( KEY3 ) ) ] ,
203
+
204
+ 'hasRoot' : [ and ( hasRoot ( KEY1 ) ) ] ,
205
+
206
+ 'hasRoot again' : [ and ( hasRoot ( KEY3 ) ) ] ,
207
+
208
+ 'author one posts' : [
209
+ and ( type ( 'post' ) , author ( AUTHOR1 ) , isPublic ( ) ) ,
210
+ startFrom ( 0 ) ,
211
+ paginate ( 25 ) ,
212
+ descending ( ) ,
213
+ ] ,
214
+
215
+ 'author two posts' : [
216
+ and ( type ( 'post' ) , author ( AUTHOR2 ) , isPublic ( ) ) ,
217
+ startFrom ( 0 ) ,
218
+ paginate ( 25 ) ,
219
+ descending ( ) ,
220
+ ] ,
221
+ }
222
+
223
+ let sbot
224
+ test ( 'setup' , ( t ) => {
225
+ const keys = ssbKeys . loadOrCreateSync ( path . join ( dir , 'secret' ) )
226
+ sbot = SecretStack ( { appKey : caps . shs } )
227
+ . use ( require ( '../' ) )
228
+ . call ( null , { keys, path : dir } )
229
+ t . end ( )
230
+ } )
231
+
232
+ for ( const title in queries ) {
233
+ test ( title , ( t ) => {
234
+ const start = Date . now ( )
235
+
236
+ sbot . db . query (
237
+ ...queries [ title ] ,
238
+ toCallback ( ( err ) => {
239
+ if ( err ) t . fail ( err )
240
+ const duration = Date . now ( ) - start
241
+ t . pass ( `duration: ${ duration } ms` )
242
+ fs . appendFileSync ( reportPath , `| ${ title } | ${ duration } ms |\n` )
243
+ t . end ( )
244
+ } )
245
+ )
246
+ } )
247
+ }
248
+
249
+ test ( 'teardown' , ( t ) => {
250
+ sbot . close ( t . end )
251
+ } )
0 commit comments