Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d499e8b
feat: Index docs in a worker
gmaclennan Aug 7, 2025
edbfe8a
don't change package-lock
gmaclennan Aug 7, 2025
232c98d
Merge branch 'main' into feat/worker-indexing
gmaclennan Aug 28, 2025
080f42c
Merge branch 'main' into feat/worker-indexing
RangerMauve Sep 15, 2025
e0af2d9
chore: Remove temp db
Sep 15, 2025
8c8177d
chore: Update imports and unit tests to new indexwriter and drizzle s…
Sep 15, 2025
3ccb675
chore: Migrate client schema, fix more tests
Sep 15, 2025
787ec20
fix: Actualy insert new cores in core migration
Sep 15, 2025
6c679f8
fix: Use proper type for data-types test
Sep 16, 2025
11f345a
chore: Remove unnecessary npmrc
Sep 16, 2025
a729ae2
fix: Get index writer worker running
Sep 18, 2025
bb45903
test: index writer worker is faster and more idle
Sep 18, 2025
1864e87
Merge branch 'main' into feat/worker-indexing
RangerMauve Sep 18, 2025
9cdc678
tests: Remove check for worker being faster
Sep 23, 2025
0337fe1
fix: Remove new buffer warning from worker
Sep 24, 2025
fac7980
test: Use index workers by default in tests
Sep 24, 2025
892f9c5
test: Ensure e2e tests use createManager util
Sep 25, 2025
875d099
fix: Close writer, reopen sqlite after reindex delete
Sep 25, 2025
4f1e4ae
tests: Fix project export types
Sep 25, 2025
ffd4d34
fix: Undo breaks to manager-basic tests
Sep 25, 2025
a3697b9
Merge branch 'main' into feat/worker-indexing
RangerMauve Sep 25, 2025
7b15b7c
fix: Wait for indexer idle in waitForSync test util
Sep 29, 2025
c362e29
fix: clean up port reuse code
Sep 29, 2025
2ada724
fix: Blocked members should only wait for auth core in initial sync
Sep 29, 2025
2471fe9
chore: cleanup blocked peer sync test asserts
Sep 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions drizzle/client/0004_lethal_carmella_unuscione.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE `cores` (
`projectPublicId` text NOT NULL,
`publicKey` blob NOT NULL,
`namespace` text NOT NULL
);
257 changes: 257 additions & 0 deletions drizzle/client/meta/0004_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
{
"version": "5",
"dialect": "sqlite",
"id": "a57dce0f-063c-47f6-b86b-4cc85722ad07",
"prevId": "3b7b9e2d-3a35-47e3-977e-b5dcbe2fd302",
"tables": {
"cores": {
"name": "cores",
"columns": {
"projectPublicId": {
"name": "projectPublicId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"publicKey": {
"name": "publicKey",
"type": "blob",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"namespace": {
"name": "namespace",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"deviceSettings": {
"name": "deviceSettings",
"columns": {
"deviceId": {
"name": "deviceId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"deviceInfo": {
"name": "deviceInfo",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"isArchiveDevice": {
"name": "isArchiveDevice",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"deviceSettings_deviceId_unique": {
"name": "deviceSettings_deviceId_unique",
"columns": [
"deviceId"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"projectSettings_backlink": {
"name": "projectSettings_backlink",
"columns": {
"versionId": {
"name": "versionId",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"projectKeys": {
"name": "projectKeys",
"columns": {
"projectId": {
"name": "projectId",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"projectPublicId": {
"name": "projectPublicId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"projectInviteId": {
"name": "projectInviteId",
"type": "blob",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"keysCipher": {
"name": "keysCipher",
"type": "blob",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"projectInfo": {
"name": "projectInfo",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'{}'"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"projectSettings": {
"name": "projectSettings",
"columns": {
"docId": {
"name": "docId",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"versionId": {
"name": "versionId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"originalVersionId": {
"name": "originalVersionId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"schemaName": {
"name": "schemaName",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updatedAt": {
"name": "updatedAt",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"links": {
"name": "links",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"deleted": {
"name": "deleted",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"projectDescription": {
"name": "projectDescription",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"projectColor": {
"name": "projectColor",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"sendStats": {
"name": "sendStats",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"defaultPresets": {
"name": "defaultPresets",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"configMetadata": {
"name": "configMetadata",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"forks": {
"name": "forks",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
7 changes: 7 additions & 0 deletions drizzle/client/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
"when": 1756331824879,
"tag": "0003_neat_magus",
"breakpoints": true
},
{
"idx": 4,
"version": "5",
"when": 1757970572349,
"tag": "0004_lethal_carmella_unuscione",
"breakpoints": true
}
]
}
18 changes: 13 additions & 5 deletions src/core-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TypedEmitter } from 'tiny-typed-emitter'
import Corestore from 'corestore'
import { debounce } from 'throttle-debounce'
import assert from 'node:assert/strict'
import { sql, eq } from 'drizzle-orm'
import { sql, eq, and } from 'drizzle-orm'

import {
HaveExtension,
Expand All @@ -11,8 +11,8 @@ import {
} from '../generated/extensions.js'
import { Logger } from '../logger.js'
import { NAMESPACES } from '../constants.js'
import { noop } from '../utils.js'
import { coresTable } from '../schema/project.js'
import { noop, projectKeyToPublicId } from '../utils.js'
import { coresTable } from '../schema/client.js'
import * as rle from './bitfield-rle.js'
import { CoreIndex } from './core-index.js'
import mapObject from 'map-obj'
Expand Down Expand Up @@ -59,7 +59,7 @@ export class CoreManager extends TypedEmitter {

/**
* @param {Object} options
* @param {import('drizzle-orm/better-sqlite3').BetterSQLite3Database} options.db Drizzle better-sqlite3 database instance
* @param {import('drizzle-orm/better-sqlite3').BetterSQLite3Database<import('../schema/client.js')>} options.db Drizzle better-sqlite3 database instance
* @param {import('@mapeo/crypto').KeyManager} options.keyManager mapeo/crypto KeyManager instance
* @param {Buffer} options.projectKey 32-byte public key of the project creator core
* @param {Buffer} [options.projectSecretKey] 32-byte secret key of the project creator core
Expand Down Expand Up @@ -95,19 +95,27 @@ export class CoreManager extends TypedEmitter {
this.#encryptionKeys = encryptionKeys
this.#autoDownload = autoDownload

const projectPublicId = projectKeyToPublicId(projectKey)

// Pre-prepare SQL statement for better performance
this.#queries = {
addCore: db
.insert(coresTable)
.values({
projectPublicId,
publicKey: sql.placeholder('publicKey'),
namespace: sql.placeholder('namespace'),
})
.onConflictDoNothing()
.prepare(),
removeCores: db
.delete(coresTable)
.where(eq(coresTable.namespace, sql.placeholder('namespace')))
.where(
and(
eq(coresTable.namespace, sql.placeholder('namespace')),
eq(coresTable.projectPublicId, projectPublicId)
)
)
.prepare(),
}

Expand Down
Loading
Loading