Remove some old code
This commit is contained in:
145
db.go
145
db.go
@@ -382,58 +382,6 @@ func (db *DBWrapper) ExpandGroupsIntoItemTypeIds(groups []int64) ([]int64, error
|
||||
return groupTypeIDs, result.Error
|
||||
}
|
||||
|
||||
func (db *DBWrapper) GetCacheEntry(cacheKey string, maxAge time.Duration) ([]byte, bool) {
|
||||
var cached CacheEntry
|
||||
err := db.db.
|
||||
Where("cache_key = ? AND created_at > ?", cacheKey, time.Now().Add(-maxAge)).
|
||||
Order("created_at DESC").
|
||||
Limit(1).
|
||||
First(&cached).Error
|
||||
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// Check if this is a 404 marker
|
||||
if len(cached.Data) == len(notFoundMarker) {
|
||||
isNotFound := true
|
||||
for i, b := range notFoundMarker {
|
||||
if cached.Data[i] != b {
|
||||
isNotFound = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if isNotFound {
|
||||
return nil, true // Cached 404
|
||||
}
|
||||
}
|
||||
|
||||
// If Data is empty, treat as not found
|
||||
if len(cached.Data) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return cached.Data, true
|
||||
}
|
||||
|
||||
func (db *DBWrapper) CacheEntry(cacheKey string, data []byte) error {
|
||||
// // Delete old entries with same key to avoid duplicates
|
||||
// db.gormDB.Where("cache_key = ?", cacheKey).Delete(&CacheEntry{})
|
||||
|
||||
// // If data is nil (404), store the special marker
|
||||
// cacheData := data
|
||||
// if data == nil {
|
||||
// cacheData = notFoundMarker
|
||||
// }
|
||||
|
||||
// return db.gormDB.Create(&CacheEntry{
|
||||
// CacheKey: cacheKey,
|
||||
// Data: cacheData,
|
||||
// CreatedAt: time.Now(),
|
||||
// }).Error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DBWrapper) SearchShips(query string, limit int) ([]models.InvType, error) {
|
||||
var ships []models.InvType
|
||||
searchPattern := "%" + strings.ToLower(query) + "%"
|
||||
@@ -476,32 +424,6 @@ func (db *DBWrapper) SearchGroups(query string, limit int) ([]models.InvGroup, e
|
||||
return groups, err
|
||||
}
|
||||
|
||||
func (db *DBWrapper) GetItemNames(ids []int32) (map[string]string, error) {
|
||||
names := make(map[string]string)
|
||||
|
||||
var items []models.InvType
|
||||
if err := db.db.Table("invTypes").
|
||||
Where("typeID IN ?", ids).
|
||||
Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, item := range items {
|
||||
names[strconv.FormatInt(int64(item.TypeID), 10)] = item.TypeName
|
||||
}
|
||||
|
||||
var systems []models.MapSolarSystem
|
||||
if err := db.db.Table("mapSolarSystems").
|
||||
Where("\"solarSystemID\" IN ?", ids).
|
||||
Find(&systems).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, system := range systems {
|
||||
names[strconv.FormatInt(int64(system.SolarSystemID), 10)] = system.SolarSystemName
|
||||
}
|
||||
|
||||
return names, nil
|
||||
}
|
||||
|
||||
func (db *DBWrapper) GetItemTypes(itemIDs []int64) ([]models.InvType, error) {
|
||||
var itemTypes []models.InvType
|
||||
res := db.db.Model(&models.InvType{}).
|
||||
@@ -530,73 +452,6 @@ func deduplicateInt64(slice []int64) []int64 {
|
||||
return result
|
||||
}
|
||||
|
||||
func (db *DBWrapper) GetModuleSlots(moduleIDs []int64) (map[int64]ModuleSlot, error) {
|
||||
mlog := logger.Default.WithPrefix("GetModuleSlots").WithPrefix(fmt.Sprintf("%v", moduleIDs))
|
||||
mlog.Debug("Starting")
|
||||
mlog.Dump("moduleIDs", moduleIDs)
|
||||
|
||||
result := make(map[int64]ModuleSlot)
|
||||
|
||||
var effects []models.DgmTypeEffect
|
||||
qres := db.db.Model(&models.DgmTypeEffect{}).
|
||||
Select("typeID, effectID").
|
||||
Where("typeID IN ? AND effectID IN (11, 12, 13, 2663)", moduleIDs).
|
||||
Find(&effects)
|
||||
if qres.Error != nil {
|
||||
mlog.Debug("Failed to get effects: %v", qres.Error)
|
||||
return nil, qres.Error
|
||||
}
|
||||
mlog.Debug("Found %d effects", qres.RowsAffected)
|
||||
mlog.Dump("effects", effects)
|
||||
|
||||
for _, e := range effects {
|
||||
var slot ModuleSlot
|
||||
switch e.EffectID {
|
||||
case 11:
|
||||
slot = ModuleSlotLow
|
||||
case 12:
|
||||
slot = ModuleSlotHigh
|
||||
case 13:
|
||||
slot = ModuleSlotMid
|
||||
case 2663:
|
||||
slot = ModuleSlotRig
|
||||
}
|
||||
result[int64(e.TypeID)] = slot
|
||||
}
|
||||
mlog.Debug("Found %d slots", len(result))
|
||||
mlog.Dump("result", result)
|
||||
|
||||
if len(result) == len(moduleIDs) {
|
||||
// All done, no more to do
|
||||
mlog.Debug("All done, no more to do")
|
||||
return result, nil
|
||||
}
|
||||
// Still have to find drones...
|
||||
|
||||
mlog.Debug("Still have to find drones...")
|
||||
var droneTypeIDs []int32
|
||||
qres = db.db.Table("invTypes").
|
||||
Select("invTypes.typeID").
|
||||
Joins("INNER JOIN invGroups ON invTypes.groupID = invGroups.groupID").
|
||||
Where("invGroups.categoryID = ?", 18).
|
||||
Where("invTypes.typeID IN ?", moduleIDs).
|
||||
Pluck("invTypes.typeID", &droneTypeIDs)
|
||||
if qres.Error != nil {
|
||||
mlog.Debug("Failed to get drone type IDs: %v", qres.Error)
|
||||
return nil, qres.Error
|
||||
}
|
||||
mlog.Debug("Found %d drone type IDs", qres.RowsAffected)
|
||||
mlog.Dump("droneTypeIDs", droneTypeIDs)
|
||||
|
||||
for _, id := range droneTypeIDs {
|
||||
result[int64(id)] = ModuleSlotDrone
|
||||
}
|
||||
mlog.Debug("Found %d drone slots", len(result))
|
||||
mlog.Dump("result", result)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (db *DBWrapper) calculateStats(params QueryParams, shipTypeIDs []int64, killmailIDs []int64, stats *FitStatistics, total int64, flog *logger.Logger) error {
|
||||
// if total == 0 {
|
||||
// return nil
|
||||
|
||||
Reference in New Issue
Block a user