Skip to content

Commit

Permalink
Remove "empty" partition from CountBase initialization
Browse files Browse the repository at this point in the history
We shouldn't be assuming that an empty partition will be used by the
user, so we shouldn't initialize all CountBase instances with the empty
partition in the config.
  • Loading branch information
samholmes committed Apr 19, 2024
1 parent 6597556 commit 1ef8d11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/CountBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ export async function createCountBase<K>(
const configData: CountBaseConfig = {
type: BaseType.CountBase,
bucketSize: Math.floor(bucketSize),
partitions: {
'': {
length: 0
}
}
partitions: {}
}
await setConfig(memlet, dbName, configData)

Expand Down
15 changes: 9 additions & 6 deletions test/CountBase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ describe('CountBase baselet', function () {
const expectedTest: CountBaseConfig = {
type: BaseType.CountBase,
bucketSize: options.bucketSize,
partitions: {
'': {
length: 0
}
}
partitions: {}
}
countbaseDb = await createCountBase(memlet, options)
expect(await getConfig(memlet, options.name)).eql(expectedTest)
})
it('empty data', async function () {
const length = await countbaseDb.length(partitionName)
expect(length).equal(0)

const [data] = await countbaseDb.query(partitionName, 0)
expect(data).equal(undefined)

const dump = await countbaseDb.dumpData()
expect(dump).keys(['config', 'data'])
expect(dump.data).deep.equals({})
})
it('insert data', async function () {
for (let i = 0; i < dataSet.length; i++) {
Expand Down Expand Up @@ -79,7 +82,7 @@ describe('CountBase baselet', function () {
it('dumpData', async () => {
const dump = await countbaseDb.dumpData()
expect(dump).keys(['config', 'data'])
expect(dump.data).keys(['', partitionName])
expect(dump.data).keys([partitionName])
expect(dump.data[partitionName]).length(dataSet.length)
})
})

0 comments on commit 1ef8d11

Please sign in to comment.