Skip to content

Commit

Permalink
Optimized workflow & app loading with X-Shuffle-Truncated header set.…
Browse files Browse the repository at this point in the history
… May add gzip more
  • Loading branch information
frikky committed May 16, 2024
1 parent edb7c80 commit 151daf2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 52 deletions.
78 changes: 31 additions & 47 deletions kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,30 +683,7 @@ func RunSelfCorrectingRequest(action Action, status int, additionalInfo, outputB

log.Printf("\n\nTOKENS (AUTOFIX API~): In: %d, Out: %d\n\n", (len(systemMessage)+len(inputData))/4, len(contentOutput)/4)

if strings.Contains(contentOutput, "```") {
// Handle ```json
start := strings.Index(contentOutput, "```json")
end := strings.Index(contentOutput, "```")
if start != -1 {
end = strings.Index(contentOutput[start+7:], "```")
}

if start != -1 && end != -1 {
contentOutput = contentOutput[start+7 : end+7]
}
}

if strings.Contains(contentOutput, "```") {
start := strings.Index(contentOutput, "```")
end := strings.Index(contentOutput[start+3:], "```")
if start != -1 {
end = strings.Index(contentOutput[start+3:], "```")
}

if start != -1 && end != -1 {
contentOutput = contentOutput[start+3 : end+3]
}
}
contentOutput = FixContentOutput(contentOutput)

log.Printf("[INFO] Autocorrect output: %s", contentOutput)

Expand Down Expand Up @@ -926,29 +903,7 @@ func UpdateActionBody(action WorkflowAppAction) (string, error) {
return "", err
}

if strings.Contains(contentOutput, "```json") {
start := strings.Index(contentOutput, "```json")
end := strings.Index(contentOutput, "```")
if start != -1 {
end = strings.Index(contentOutput[start+8:], "```")
}

if start != -1 && end != -1 {
contentOutput = contentOutput[start+7 : end+7]
}
}

if strings.Contains(contentOutput, "```") {
start := strings.Index(contentOutput, "```")
end := strings.Index(contentOutput[start+3:], "```")
if start != -1 {
end = strings.Index(contentOutput[start+3:], "```")
}

if start != -1 && end != -1 {
contentOutput = contentOutput[start+3 : end+3]
}
}
contentOutput = FixContentOutput(contentOutput)

output := map[string]interface{}{}
err = json.Unmarshal([]byte(contentOutput), &output)
Expand Down Expand Up @@ -1214,3 +1169,32 @@ func uploadParameterBase(ctx context.Context, orgId, appId, actionName, paramNam

return nil
}

func FixContentOutput(contentOutput string) string {
if strings.Contains(contentOutput, "```") {
// Handle ```json
start := strings.Index(contentOutput, "```json")
end := strings.Index(contentOutput, "```")
if start != -1 {
end = strings.Index(contentOutput[start+7:], "```")
}

if start != -1 && end != -1 {
contentOutput = contentOutput[start+7 : end+7]
}
}

if strings.Contains(contentOutput, "```") {
start := strings.Index(contentOutput, "```")
end := strings.Index(contentOutput[start+3:], "```")
if start != -1 {
end = strings.Index(contentOutput[start+3:], "```")
}

if start != -1 && end != -1 {
contentOutput = contentOutput[start+3 : end+3]
}
}

return contentOutput
}
36 changes: 31 additions & 5 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -3698,6 +3698,10 @@ func GetWorkflows(resp http.ResponseWriter, request *http.Request) {
continue
}

if project.Environment == "cloud" && workflow.ExecutionEnvironment == "onprem" {
continue
}

newActions := []Action{}
for _, action := range workflow.Actions {
// Removed because of exports. These are needed there.
Expand All @@ -3707,18 +3711,40 @@ func GetWorkflows(resp http.ResponseWriter, request *http.Request) {
newActions = append(newActions, action)
}

workflow.Actions = newActions
//workflow.Actions = newActions


// Skipping these as they're related to onprem workflows in cloud (orborus)
if project.Environment == "cloud" && workflow.ExecutionEnvironment == "onprem" {
continue
}

usecaseIds = append(usecaseIds, workflow.UsecaseIds...)
newWorkflows = append(newWorkflows, workflow)
}

workflows = newWorkflows
if project.Environment == "cloud" && len(newWorkflows) > 15 {
log.Printf("[WARNING] Removed workflow actions for user %s (%s) in org %s (%s)", user.Username, user.Id, user.ActiveOrg.Name, user.ActiveOrg.Id)

for workflowIndex, _ := range newWorkflows {
newWorkflows[workflowIndex].Actions = []Action{}
newWorkflows[workflowIndex].Triggers = []Trigger{}
newWorkflows[workflowIndex].Branches = []Branch{}
newWorkflows[workflowIndex].VisualBranches = []Branch{}
newWorkflows[workflowIndex].Image = ""

newWorkflows[workflowIndex].Description = ""
newWorkflows[workflowIndex].Blogpost = ""

if len(newWorkflows[workflowIndex].Org) > 0 {
for orgIndex, _ := range newWorkflows[workflowIndex].Org {
newWorkflows[workflowIndex].Org[orgIndex].Image = ""
}
}

newWorkflows[workflowIndex].ExecutingOrg.Image = ""
}

// Add header that this is a limited response
resp.Header().Set("X-Shuffle-Truncated", "true")
}

// Get the org as well to manage priorities
// Only happens on first load, so it's like once per session~
Expand Down

0 comments on commit 151daf2

Please sign in to comment.