(db *gorm.DB, eid int64, entityIDs []int64)
| 195 | } |
| 196 | |
| 197 | func 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 | |
| 230 | func GetEntityVectorCollectionName(eid int64) string { |
| 231 | return fmt.Sprintf("entity_eid_%d", eid) |
no test coverage detected