-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
176 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @jest-environment composedb | ||
*/ | ||
|
||
import { SyncOptions } from '@ceramicnetwork/common' | ||
import { ModelInstanceDocument } from '@ceramicnetwork/stream-model-instance' | ||
import { StreamID } from '@ceramicnetwork/streamid' | ||
import { Composite } from '@composedb/devtools' | ||
import { favoriteSchema } from '@composedb/test-schemas' | ||
import type { CeramicAPI } from '@composedb/types' | ||
|
||
import { createDeterministicKey } from '../src/deterministic' | ||
import { DocumentLoader } from '../src/loader' | ||
|
||
declare global { | ||
const ceramic: CeramicAPI | ||
} | ||
|
||
describe('latency', () => { | ||
const controller = ceramic.did!.id | ||
let modelID: string | ||
|
||
beforeAll(async () => { | ||
const composite = await Composite.create({ ceramic, schema: favoriteSchema }) | ||
modelID = composite.getModelID('Favorite')! | ||
}) | ||
|
||
test('using ModelInstanceDocument.set()', async () => { | ||
const model = StreamID.fromString(modelID) | ||
console.time('using ModelInstanceDocument.set()') | ||
await ModelInstanceDocument.set(ceramic, { controller, model }, ['one', 'one']) | ||
console.timeLog('using ModelInstanceDocument.set()', 'first load') | ||
await ModelInstanceDocument.set(ceramic, { controller, model }, ['one', 'one']) | ||
console.timeEnd('using ModelInstanceDocument.set()') | ||
}) | ||
|
||
test('using ceramic.multiQuery()', async () => { | ||
const { id, genesis } = await createDeterministicKey({ | ||
controller, | ||
model: modelID, | ||
unique: ['two', 'two'], | ||
}) | ||
console.time('using ceramic.multiQuery()') | ||
await ceramic.multiQuery([{ streamId: id, genesis, opts: { sync: SyncOptions.NEVER_SYNC } }]) | ||
console.timeLog('using ceramic.multiQuery()', 'first load') | ||
await ceramic.multiQuery([{ streamId: id, genesis, opts: { sync: SyncOptions.NEVER_SYNC } }]) | ||
console.timeEnd('using ceramic.multiQuery()') | ||
}) | ||
|
||
test('using loader.loadSet()', async () => { | ||
const loader = new DocumentLoader({ ceramic }) | ||
console.time('using loader.loadSet()') | ||
await loader.loadSet(controller, modelID, ['three', 'three']) | ||
console.timeLog('using loader.loadSet()', 'first load') | ||
await loader.loadSet(controller, modelID, ['three', 'three']) | ||
console.timeEnd('using loader.loadSet()') | ||
}) | ||
|
||
test('using ceramic.index.query()', async () => { | ||
console.time('ceramic.index.query()') | ||
await ceramic.index.query({ | ||
account: controller, | ||
models: [modelID], | ||
first: 1, | ||
queryFilters: { where: { docID: { equalTo: 'four' }, tag: { equalTo: 'four' } } }, | ||
}) | ||
console.timeLog('ceramic.index.query()', 'first load') | ||
await ceramic.index.query({ | ||
account: controller, | ||
models: [modelID], | ||
first: 1, | ||
queryFilters: { where: { docID: { equalTo: 'four' }, tag: { equalTo: 'four' } } }, | ||
}) | ||
console.timeEnd('ceramic.index.query()') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.