| 1 | package sessioncatalog |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | // Caller holds mutationMu across preparation and publication so an obsolete |
| 6 | // source observation cannot overwrite a later committed mutation. |
| 7 | func (c *Catalog) prepareUpsertRecords(ctx context.Context, records []SessionRecord, dirtyDirectories map[string]DirectoryTarget, mode sessionUpsertMode) ([]SessionRecord, error) { |
| 8 | filtered := records[:0] |
| 9 | for _, record := range records { |
| 10 | pathKey := c.pathKey(record.Path) |
| 11 | if c.pathMutationAllowed(pathKey, record.enqueueSequence) { |
| 12 | filtered = append(filtered, record) |
| 13 | } |
| 14 | } |
| 15 | records = filtered |
| 16 | if len(records) == 0 { |
| 17 | return records, nil |
| 18 | } |
| 19 | if mode == upsertExactSource { |
| 20 | prepared := make([]SessionRecord, 0, len(records)) |
| 21 | for _, raw := range records { |
| 22 | record, skip, projectionDirty, err := c.prepareExactPathProjection(ctx, raw) |
| 23 | if err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | if projectionDirty { |
| 27 | dirtyDirectories[c.pathKey(record.Directory)] = DirectoryTarget{ |
| 28 | Path: record.Directory, Scope: record.Scope, WorkspaceRoot: record.WorkspaceRoot, |
| 29 | } |
| 30 | } |
| 31 | if !skip { |
| 32 | prepared = append(prepared, record) |
| 33 | } |
| 34 | } |
| 35 | records = prepared |
| 36 | if len(records) == 0 { |
| 37 | return records, nil |
| 38 | } |
| 39 | } |
| 40 | return records, nil |
| 41 | } |
| 42 |