-
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. (#122)
Co-authored-by: James Kwon <[email protected]>
- Loading branch information
1 parent
76ee821
commit 5753550
Showing
7 changed files
with
263 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,24 @@ | ||
package entity | ||
|
||
import "registry-backend/ent" | ||
|
||
type AlgoliaNode struct { | ||
ObjectID string `json:"objectID"` | ||
*ent.Node | ||
LatestVersion *struct { | ||
*ent.NodeVersion | ||
ComfyNodes map[string]*ent.ComfyNode `json:"comfy_nodes"` | ||
} `json:"latest_version"` | ||
} | ||
|
||
func (n *AlgoliaNode) ToEntNode() *ent.Node { | ||
node := n.Node | ||
if n.LatestVersion != nil { | ||
nv := n.LatestVersion.NodeVersion | ||
for _, v := range n.LatestVersion.ComfyNodes { | ||
nv.Edges.ComfyNodes = append(nv.Edges.ComfyNodes, v) | ||
} | ||
node.Edges.Versions = []*ent.NodeVersion{nv} | ||
} | ||
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,42 @@ | ||
package mapper | ||
|
||
import ( | ||
"registry-backend/ent" | ||
"registry-backend/entity" | ||
) | ||
|
||
func AlgoliaNodeFromEntNode(node *ent.Node) entity.AlgoliaNode { | ||
n := entity.AlgoliaNode{ | ||
ObjectID: node.ID, | ||
Node: new(ent.Node), | ||
} | ||
*n.Node = *node | ||
n.Edges = ent.NodeEdges{} | ||
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 = &struct { | ||
*ent.NodeVersion | ||
ComfyNodes map[string]*ent.ComfyNode `json:"comfy_nodes"` | ||
}{ | ||
NodeVersion: new(ent.NodeVersion), | ||
ComfyNodes: make(map[string]*ent.ComfyNode, len(lv.Edges.ComfyNodes)), | ||
} | ||
*n.LatestVersion.NodeVersion = *lv | ||
n.LatestVersion.NodeVersion.Edges = ent.NodeVersionEdges{} | ||
for _, v := range lv.Edges.ComfyNodes { | ||
n.LatestVersion.ComfyNodes[v.ID] = v | ||
} | ||
|
||
return n | ||
} |
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
Oops, something went wrong.