| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "crypto/sha256" |
| 5 | "encoding/json" |
| 6 | "sync" |
| 7 | |
| 8 | "reasonix/desktop/internal/workspacestate" |
| 9 | ) |
| 10 | |
| 11 | type organizationReadCache struct { |
| 12 | mu sync.Mutex |
| 13 | entries map[[32]byte]workspacestate.Organization |
| 14 | } |
| 15 | |
| 16 | func (c *organizationReadCache) get(key [32]byte) (workspacestate.Organization, bool) { |
| 17 | c.mu.Lock() |
| 18 | defer c.mu.Unlock() |
| 19 | o, ok := c.entries[key] |
| 20 | return o.Clone(), ok |
| 21 | } |
| 22 | |
| 23 | func (c *organizationReadCache) put(key [32]byte, o workspacestate.Organization) { |
| 24 | c.mu.Lock() |
| 25 | defer c.mu.Unlock() |
| 26 | if c.entries == nil || len(c.entries) >= 32 { |
| 27 | c.entries = map[[32]byte]workspacestate.Organization{} |
| 28 | } |
| 29 | c.entries[key] = o.Clone() |
| 30 | } |
| 31 | |
| 32 | func (a *App) organizationImportKey(scope, root string, state workspacestate.State, id string, projects any) ([32]byte, bool) { |
| 33 | var zero [32]byte |
| 34 | catalog := a.sessionCatalog.Load() |
| 35 | if catalog == nil { |
| 36 | return zero, false |
| 37 | } |
| 38 | availability := a.catalogWorkspaceAvailability(catalog, scope, root) |
| 39 | if !availability.usable || !availability.complete { |
| 40 | return zero, false |
| 41 | } |
| 42 | body, err := json.Marshal([]any{state.Workspaces[id], state.SourceMappings, state.Presentation, projects, a.currentSessionCatalogStatus().Revision}) |
| 43 | return sha256.Sum256(body), err == nil |
| 44 | } |
| 45 |