GetProjectByResourceID gets a project by its globally unique resource ID without workspace filter. For use by runners that resolve workspace from the loaded entity.
(ctx context.Context, resourceID string)
| 21 | // GetProjectByResourceID gets a project by its globally unique resource ID without workspace filter. |
| 22 | // For use by runners that resolve workspace from the loaded entity. |
| 23 | func (s *Store) GetProjectByResourceID(ctx context.Context, resourceID string) (*ProjectMessage, error) { |
| 24 | if v, ok := s.projectCache.Get(resourceID); ok && s.enableCache { |
| 25 | return v, nil |
| 26 | } |
| 27 | |
| 28 | q := qb.Q().Space("SELECT resource_id, workspace, name, setting, deleted FROM project WHERE resource_id = ?", resourceID) |
| 29 | query, args, err := q.ToSQL() |
| 30 | if err != nil { |
| 31 | return nil, err |
| 32 | } |
| 33 | |
| 34 | var project ProjectMessage |
| 35 | var payload []byte |
| 36 | if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan( |
| 37 | &project.ResourceID, |
| 38 | &project.Workspace, |
| 39 | &project.Title, |
| 40 | &payload, |
| 41 | &project.Deleted, |
| 42 | ); err != nil { |
| 43 | if err == sql.ErrNoRows { |
| 44 | return nil, nil |
| 45 | } |
| 46 | return nil, err |
| 47 | } |
| 48 | setting := &storepb.Project{} |
| 49 | if err := common.ProtojsonUnmarshaler.Unmarshal(payload, setting); err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | project.Setting = setting |
| 53 | s.storeProjectCache(&project) |
| 54 | return &project, nil |
| 55 | } |
| 56 | |
| 57 | // GetInstanceByResourceID gets an instance by its globally unique resource ID without workspace filter. |
| 58 | // For use by runners that resolve workspace from the loaded entity. |
no test coverage detected