MCPcopy
hub / github.com/wavetermdev/waveterm / AppendIJson

Method AppendIJson

pkg/filestore/blockstore.go:323–362  ·  view source on GitHub ↗
(ctx context.Context, zoneId string, name string, command map[string]any)

Source from the content-addressed store, hash-verified

321}
322
323func (s *FileStore) AppendIJson(ctx context.Context, zoneId string, name string, command map[string]any) error {
324 data, err := ijson.ValidateAndMarshalCommand(command)
325 if err != nil {
326 return err
327 }
328 return withLock(s, zoneId, name, func(entry *CacheEntry) error {
329 err := entry.loadFileIntoCache(ctx)
330 if err != nil {
331 return err
332 }
333 if !entry.File.Opts.IJson {
334 return fmt.Errorf("file %s:%s is not an ijson file", zoneId, name)
335 }
336 partMap := entry.File.computePartMap(entry.File.Size, int64(len(data)))
337 incompleteParts := incompletePartsFromMap(partMap)
338 if len(incompleteParts) > 0 {
339 err = entry.loadDataPartsIntoCache(ctx, incompleteParts)
340 if err != nil {
341 return err
342 }
343 }
344 oldSize := entry.File.Size
345 entry.writeAt(entry.File.Size, data, false)
346 entry.writeAt(entry.File.Size, []byte("\n"), false)
347 if oldSize == 0 {
348 return nil
349 }
350 // check if we should compact
351 numCmds := metaIncrement(entry.File, IJsonNumCommands, 1)
352 numBytes := metaIncrement(entry.File, IJsonIncrementalBytes, len(data)+1)
353 incRatio := float64(numBytes) / float64(entry.File.Size)
354 if numCmds > IJsonHighCommands || incRatio >= IJsonHighRatio || (numCmds > IJsonLowCommands && incRatio >= IJsonLowRatio) {
355 err := s.compactIJson(ctx, entry)
356 if err != nil {
357 return err
358 }
359 }
360 return nil
361 })
362}
363
364func (s *FileStore) GetAllZoneIds(ctx context.Context) ([]string, error) {
365 return dbGetAllZoneIds(ctx)

Callers 1

TestIJsonFunction · 0.80

Calls 9

compactIJsonMethod · 0.95
withLockFunction · 0.85
incompletePartsFromMapFunction · 0.85
metaIncrementFunction · 0.85
loadFileIntoCacheMethod · 0.80
computePartMapMethod · 0.80
writeAtMethod · 0.80

Tested by 1

TestIJsonFunction · 0.64