project_key.js 636 B

1234567891011121314151617181920
  1. // Keep in sync with services/history-v1/storage/lib/project_key.js
  2. import path from 'node:path'
  3. //
  4. // The advice in http://docs.aws.amazon.com/AmazonS3/latest/dev/
  5. // request-rate-perf-considerations.html is to avoid sequential key prefixes,
  6. // so we reverse the project ID part of the key as they suggest.
  7. //
  8. export function format(projectId) {
  9. const prefix = naiveReverse(pad(projectId))
  10. return path.join(prefix.slice(0, 3), prefix.slice(3, 6), prefix.slice(6))
  11. }
  12. export function pad(number) {
  13. return (number || 0).toString().padStart(9, '0')
  14. }
  15. function naiveReverse(string) {
  16. return string.split('').reverse().join('')
  17. }