Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -14562,12 +14562,46 @@ func GetWorkflowAppConfig(resp http.ResponseWriter, request *http.Request) {
}
}

// Used to cache pre-algolia lookup
unescaped, err := url.QueryUnescape(app.Name)
unescapedName, err := url.QueryUnescape(app.Name)
if err == nil {
encodedAppName := fmt.Sprintf("workflowapp_cache_%s", unescaped)

SetCache(context.Background(), encodedAppName, []byte(fmt.Sprintf(`{"success": true, "id": "%s"}`, app.ID)), 86400)
type AppCacheData struct {
Success bool `json:"success"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}

cacheData := AppCacheData{
Success: true,
ID: app.ID,
Name: app.Name,
Description: app.Description,
}

cachePayload, err := json.Marshal(cacheData)
if err != nil {
log.Printf("[WARNING] Failed marshalling app cache payload: %s", err)
cachePayload = []byte(fmt.Sprintf(`{"success": true, "id": "%s"}`, app.ID))
}

// 1. Cache by actual app name
primarySlug := strings.ToLower(strings.ReplaceAll(unescapedName, " ", "_"))
primaryKey := fmt.Sprintf("workflowapp_cache_%s", primarySlug)
SetCache(context.Background(), primaryKey, cachePayload, 86400)
log.Printf("[INFO] App cache set: %s (%s)", primaryKey, app.ID)

// 2. Cache by search alias (e.g., "outlook") if provided by the frontend
aliasQuery := request.URL.Query().Get("alias")
if len(aliasQuery) > 0 {
aliasSlug := strings.ToLower(strings.ReplaceAll(aliasQuery, " ", "_"))
aliasKey := fmt.Sprintf("workflowapp_cache_%s", aliasSlug)

// Only set if alias is different from the primary name
if aliasKey != primaryKey {
SetCache(context.Background(), aliasKey, cachePayload, 86400)
log.Printf("[INFO] App alias cache set: %s -> %s", aliasKey, app.ID)
}
}
}
}

Expand Down
Loading