| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "reflect" |
| 6 | ) |
| 7 | |
| 8 | func (a *App) historicalCatalogPublisher(ctx context.Context, positions map[string]int) func([]historicalCatalogEntry) { |
| 9 | c := &a.historicalImports |
| 10 | return func(batch []historicalCatalogEntry) { |
| 11 | c.mu.Lock() |
| 12 | if c.stopped || ctx.Err() != nil { |
| 13 | c.mu.Unlock() |
| 14 | return |
| 15 | } |
| 16 | changed := false |
| 17 | for _, entry := range batch { |
| 18 | if i, exists := positions[entry.node.Key]; exists { |
| 19 | if !reflect.DeepEqual(c.catalog[i], entry) { |
| 20 | c.catalog[i], changed = entry, true |
| 21 | } |
| 22 | } else { |
| 23 | positions[entry.node.Key] = len(c.catalog) |
| 24 | c.catalog = append(c.catalog, entry) |
| 25 | changed = true |
| 26 | } |
| 27 | } |
| 28 | if changed { |
| 29 | c.catalogRevision++ |
| 30 | } |
| 31 | c.mu.Unlock() |
| 32 | if changed { |
| 33 | a.emitProjectTreeChangedEvent() |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 |