@earth-app/collegedb
    Preparing search index...

    Function getShardStats

    • Gets statistics for all shards

      Returns usage statistics for all known shards, including key counts and last updated timestamps. First attempts to get real-time statistics from the Durable Object coordinator, then falls back to KV-based counting.

      This information is useful for:

      • Load balancing decisions
      • Monitoring shard utilization
      • Capacity planning
      • Performance analysis

      Returns Promise<ShardStats[]>

      Promise resolving to array of shard statistics

      const stats = await getShardStats();
      stats.forEach(shard => {
      console.log(`${shard.binding}: ${shard.count} keys`);
      if (shard.lastUpdated) {
      console.log(` Last updated: ${new Date(shard.lastUpdated)}`);
      }
      });

      // Find most loaded shard
      const mostLoaded = stats.reduce((prev, current) =>
      (prev.count > current.count) ? prev : current
      );
      console.log(`Most loaded shard: ${mostLoaded.binding} (${mostLoaded.count} keys)`);