MCPcopy Create free account
hub / github.com/53AI/53AIHub / DeleteOrphanEntitiesByIDsWithDB

Function DeleteOrphanEntitiesByIDsWithDB

api/model/entity.go:197–228  ·  view source on GitHub ↗
(db *gorm.DB, eid int64, entityIDs []int64)

Source from the content-addressed store, hash-verified

195}
196
197func DeleteOrphanEntitiesByIDsWithDB(db *gorm.DB, eid int64, entityIDs []int64) error {
198 if db == nil {
199 return errors.New("db is nil")
200 }
201 if eid <= 0 {
202 return errors.New("eid is empty")
203 }
204 if len(entityIDs) == 0 {
205 return nil
206 }
207
208 uniq := make(map[int64]struct{}, len(entityIDs))
209 cleaned := make([]int64, 0, len(entityIDs))
210 for _, id := range entityIDs {
211 if id <= 0 {
212 continue
213 }
214 if _, ok := uniq[id]; ok {
215 continue
216 }
217 uniq[id] = struct{}{}
218 cleaned = append(cleaned, id)
219 }
220 if len(cleaned) == 0 {
221 return nil
222 }
223
224 return db.Model(&Entity{}).
225 Where("eid = ? AND id IN ?", eid, cleaned).
226 Where("NOT EXISTS (SELECT 1 FROM entity_chunk_relations WHERE entity_chunk_relations.eid = ? AND entity_chunk_relations.entity_id = entities.id)", eid).
227 Delete(&Entity{}).Error
228}
229
230func GetEntityVectorCollectionName(eid int64) string {
231 return fmt.Sprintf("entity_eid_%d", eid)

Callers 3

deleteFileWithCascadeFunction · 0.85
cascadeDeleteFileDataFunction · 0.85
DeleteLibraryFunction · 0.85

Calls 2

DeleteMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected