Skip to content

Commit fe3efe5

Browse files
committed
feat(sharding): simplify sharding logic by always using sharded categories and removing inline category writing
1 parent bef296b commit fe3efe5

4 files changed

Lines changed: 3 additions & 40 deletions

File tree

src/sync/operations/push.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
markOrphanedFiles,
1010
buildPushContext,
1111
} from './helpers.js';
12-
import { shouldShard, writeShardedCategory, writeInlineItemCategory } from './sharding.js';
12+
import { writeShardedCategory } from './sharding.js';
1313
import {
1414
type ItemCategoryInfo,
1515
type ItemInfo,
@@ -169,14 +169,9 @@ function packItemCategoryData(
169169
ctx.files[filename] = { content: null };
170170
}
171171
const newItems = removeItemsById(processed, tombResult.itemsToRemove);
172-
const totalEntries = Object.keys(newItems).length + Object.keys(tombResult.tombstones).length;
173172

174-
// Use sharding if item count exceeds threshold
175-
if (shouldShard(totalEntries)) {
176-
writeShardedCategory(category, newItems, tombResult.tombstones, ctx);
177-
} else {
178-
writeInlineItemCategory(category, newItems, tombResult.tombstones, ctx);
179-
}
173+
// Always use sharding for item categories
174+
writeShardedCategory(category, newItems, tombResult.tombstones, ctx);
180175

181176
return filenames;
182177
}

src/sync/operations/sharding.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,14 @@
66

77
import { calculateChecksum } from '../packer.js';
88
import {
9-
type ItemCategoryInfo,
109
type ItemInfo,
1110
type CategoryShard,
1211
type ShardedCategoryRef,
1312
getShardFilename,
14-
shouldShard,
1513
} from '../../types/index.js';
1614
import type { Tombstone } from '../../types/manifest.js';
1715
import type { PushContext, SyncCategory } from './types.js';
1816

19-
export { shouldShard };
20-
21-
/** Write inline item category (not sharded) to manifest */
22-
export function writeInlineItemCategory(
23-
category: SyncCategory,
24-
items: Record<string, ItemInfo>,
25-
tombstones: Record<string, Tombstone>,
26-
ctx: PushContext
27-
): void {
28-
ctx.manifest.categories[category] = {
29-
type: 'items',
30-
items,
31-
tombstones,
32-
itemCount: Object.keys(items).length,
33-
lastModified: ctx.now,
34-
lastModifiedBy: ctx.machineId,
35-
vectorClock: { [ctx.machineId]: ctx.newClock[ctx.machineId] ?? 1 },
36-
} satisfies ItemCategoryInfo;
37-
}
38-
3917
/**
4018
* Write a sharded category (items stored in separate shard file).
4119
*/

src/types/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export {
4141
// Sharded manifest helpers
4242
isShardedRef,
4343
getShardFilename,
44-
SHARDING_THRESHOLD,
45-
shouldShard,
4644
} from './manifest.js';
4745

4846
// Sync Operations

src/types/manifest.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,6 @@ export function getShardFilename(category: SyncCategory): string {
125125
return `manifest-${category}.json`;
126126
}
127127

128-
/** Categories that should use sharding when item count exceeds threshold */
129-
export const SHARDING_THRESHOLD = 100;
130-
131-
/** Check if a category should be sharded based on item count */
132-
export function shouldShard(itemCount: number): boolean {
133-
return itemCount >= SHARDING_THRESHOLD;
134-
}
135-
136128
/** Content of a category shard file */
137129
export interface CategoryShard {
138130
/** Category this shard belongs to */

0 commit comments

Comments
 (0)