@@ -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 AUTHOR1 = '@ZngOKXHjrvG+cy7Gjx5pSFunUqcePfmDQQxoUlHFUdU=.ed2551'
176
+ const AUTHOR2 = '@58u/J9+5bOXeYRDCYQ9cJ7kklghIpQFPBYxlhKq1/qs=.ed2551'
177
+
178
+ const queries = {
179
+ 'key one initial' : [ and ( key ( KEY1 ) ) ] ,
180
+
181
+ 'key two' : [ and ( key ( KEY2 ) ) ] ,
182
+
183
+ 'key one again' : [ and ( key ( KEY1 ) ) ] ,
184
+
185
+ 'latest root posts' : [
186
+ and ( type ( 'post' ) , isRoot ( ) , isPublic ( ) ) ,
187
+ startFrom ( 0 ) ,
188
+ paginate ( 25 ) ,
189
+ descending ( ) ,
190
+ ] ,
191
+
192
+ 'latest posts' : [
193
+ and ( type ( 'post' ) , isPublic ( ) ) ,
194
+ startFrom ( 0 ) ,
195
+ paginate ( 25 ) ,
196
+ descending ( ) ,
197
+ ] ,
198
+
199
+ 'votes one initial' : [ and ( votesFor ( KEY1 ) ) ] ,
200
+
201
+ 'votes one' : [ and ( votesFor ( KEY1 ) ) ] ,
202
+
203
+ 'votes again' : [ and ( votesFor ( KEY1 ) ) ] ,
204
+
205
+ hasRoot : [ and ( hasRoot ( KEY1 ) ) ] ,
206
+
207
+ 'hasRoot again' : [ and ( hasRoot ( KEY1 ) ) ] ,
208
+
209
+ 'author one posts' : [
210
+ and ( type ( 'post' ) , author ( AUTHOR1 ) , isPublic ( ) ) ,
211
+ startFrom ( 0 ) ,
212
+ paginate ( 25 ) ,
213
+ descending ( ) ,
214
+ ] ,
215
+
216
+ 'author two posts' : [
217
+ and ( type ( 'post' ) , author ( AUTHOR2 ) , isPublic ( ) ) ,
218
+ startFrom ( 0 ) ,
219
+ paginate ( 25 ) ,
220
+ descending ( ) ,
221
+ ] ,
222
+ }
223
+
224
+ let sbot
225
+ test ( 'setup' , ( t ) => {
226
+ const keys = ssbKeys . loadOrCreateSync ( path . join ( dir , 'secret' ) )
227
+ sbot = SecretStack ( { appKey : caps . shs } )
228
+ . use ( require ( '../' ) )
229
+ . call ( null , { keys, path : dir } )
230
+ t . end ( )
231
+ } )
232
+
233
+ for ( const title in queries ) {
234
+ test ( title , ( t ) => {
235
+ const start = Date . now ( )
236
+
237
+ sbot . db . query (
238
+ ...queries [ title ] ,
239
+ toCallback ( ( err ) => {
240
+ if ( err ) t . fail ( err )
241
+ const duration = Date . now ( ) - start
242
+ t . pass ( `duration: ${ duration } ms` )
243
+ t . end ( )
244
+ } )
245
+ )
246
+ } )
247
+ }
248
+
249
+ test ( 'teardown' , ( t ) => {
250
+ sbot . close ( t . end )
251
+ } )
0 commit comments