-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Index Comfy Nodes From Latest Version to Algolia Search Index. (#129)
* Index comfy nodes from the latest version to Algolia Search Index. * specify algolia field --------- Co-authored-by: James Kwon <[email protected]>
- Loading branch information
1 parent
658065f
commit 61cbf41
Showing
7 changed files
with
339 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package entity | ||
|
||
import ( | ||
"registry-backend/ent" | ||
"registry-backend/ent/schema" | ||
"time" | ||
) | ||
|
||
type AlgoliaNode struct { | ||
ObjectID string `json:"objectID"` | ||
|
||
ID string `json:"id,omitempty"` | ||
CreateTime time.Time `json:"create_time,omitempty"` | ||
UpdateTime time.Time `json:"update_time,omitempty"` | ||
PublisherID string `json:"publisher_id,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
Description string `json:"description,omitempty"` | ||
Category string `json:"category,omitempty"` | ||
Author string `json:"author,omitempty"` | ||
License string `json:"license,omitempty"` | ||
RepositoryURL string `json:"repository_url,omitempty"` | ||
IconURL string `json:"icon_url,omitempty"` | ||
Tags []string `json:"tags,omitempty"` | ||
TotalInstall int64 `json:"total_install,omitempty"` | ||
TotalStar int64 `json:"total_star,omitempty"` | ||
TotalReview int64 `json:"total_review,omitempty"` | ||
Status schema.NodeStatus `json:"status,omitempty"` | ||
StatusDetail string `json:"status_detail,omitempty"` | ||
|
||
LatestVersion string `json:"latest_version,omitempty"` | ||
LatestVersionStatus schema.NodeVersionStatus `json:"latest_version_status,omitempty"` | ||
ComfyNodeNames []string `json:"comfy_nodes,omitempty"` | ||
} | ||
|
||
func (n *AlgoliaNode) ToEntNode() *ent.Node { | ||
node := &ent.Node{ | ||
ID: n.ID, | ||
CreateTime: n.CreateTime, | ||
UpdateTime: n.UpdateTime, | ||
PublisherID: n.PublisherID, | ||
Name: n.Name, | ||
Description: n.Description, | ||
Category: n.Category, | ||
Author: n.Author, | ||
License: n.License, | ||
RepositoryURL: n.RepositoryURL, | ||
IconURL: n.IconURL, | ||
Tags: n.Tags, | ||
TotalInstall: n.TotalInstall, | ||
TotalStar: n.TotalStar, | ||
TotalReview: n.TotalReview, | ||
Status: n.Status, | ||
StatusDetail: n.StatusDetail, | ||
} | ||
if n.LatestVersion == "" { | ||
return node | ||
} | ||
|
||
node.Edges = ent.NodeEdges{ | ||
Versions: []*ent.NodeVersion{{ | ||
NodeID: n.ID, | ||
Version: n.LatestVersion, | ||
Status: n.LatestVersionStatus, | ||
}}, | ||
} | ||
if len(n.ComfyNodeNames) == 0 { | ||
return node | ||
} | ||
|
||
node.Edges.Versions[0].Edges = ent.NodeVersionEdges{ | ||
ComfyNodes: make([]*ent.ComfyNode, 0, len(n.ComfyNodeNames)), | ||
} | ||
for _, name := range n.ComfyNodeNames { | ||
node.Edges.Versions[0].Edges.ComfyNodes = append(node.Edges.Versions[0].Edges.ComfyNodes, &ent.ComfyNode{ | ||
ID: name, | ||
}) | ||
} | ||
return node | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package mapper | ||
|
||
import ( | ||
"registry-backend/ent" | ||
"registry-backend/entity" | ||
) | ||
|
||
func AlgoliaNodeFromEntNode(node *ent.Node) entity.AlgoliaNode { | ||
n := entity.AlgoliaNode{ | ||
ObjectID: node.ID, | ||
ID: node.ID, | ||
CreateTime: node.CreateTime, | ||
UpdateTime: node.UpdateTime, | ||
PublisherID: node.PublisherID, | ||
Name: node.Name, | ||
Description: node.Description, | ||
Category: node.Category, | ||
Author: node.Author, | ||
License: node.License, | ||
RepositoryURL: node.RepositoryURL, | ||
IconURL: node.IconURL, | ||
Tags: node.Tags, | ||
TotalInstall: node.TotalInstall, | ||
TotalStar: node.TotalStar, | ||
TotalReview: node.TotalReview, | ||
Status: node.Status, | ||
StatusDetail: node.StatusDetail, | ||
|
||
LatestVersion: "", | ||
LatestVersionStatus: "", | ||
} | ||
|
||
if node.Edges.Versions == nil { | ||
return n | ||
} | ||
|
||
var lv *ent.NodeVersion | ||
for _, v := range node.Edges.Versions { | ||
if lv == nil { | ||
lv = v | ||
} else if v.CreateTime.After(lv.CreateTime) { | ||
lv = v | ||
} | ||
} | ||
n.LatestVersion = lv.Version | ||
n.LatestVersionStatus = lv.Status | ||
n.ComfyNodeNames = make([]string, 0, len(lv.Edges.ComfyNodes)) | ||
for _, v := range lv.Edges.ComfyNodes { | ||
n.ComfyNodeNames = append(n.ComfyNodeNames, v.ID) | ||
} | ||
|
||
return n | ||
} |
Oops, something went wrong.