Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions db/elasticsearch_mapsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,26 @@ func UpdateElasticSearchMapDifficulty(id int, md5 string, difficultyRating float
return nil
}

// UpdateElasticSearchMapClanRanked Updates the map to set clan ranked status and date
func UpdateElasticSearchMapClanRanked(id int, clanRanked bool, dateClanRanked int64) error {
data, err := json.Marshal(map[string]interface{}{
"doc": map[string]interface{}{
"is_clan_ranked": clanRanked,
"date_clan_ranked": time.UnixMilli(dateClanRanked),
},
})
if err != nil {
return err
}

resp, err := ElasticSearch.Update(elasticMapSearchIndex, strconv.Itoa(id), bytes.NewReader(data), ElasticSearch.Update.WithRetryOnConflict(3))
if err != nil {
return err
}
resp.Body.Close()
return nil
}

// DeleteElasticSearchMapset Deletes an individual mapset in elastic
func DeleteElasticSearchMapset(id int) error {
queryMap := map[string]interface{}{
Expand Down
12 changes: 9 additions & 3 deletions db/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,18 @@ func UpdateMapDifficultyRating(id int, md5 string, difficultyRating float64) err

// UpdateMapClanRanked Updates the clan ranked status of a map
func UpdateMapClanRanked(id int, clanRanked bool) error {
dateClanRanked := time.Now().UnixMilli()
result := SQL.Model(&MapQua{}).
Where("id = ?", id).
Update("clan_ranked", clanRanked).
Update("date_clan_ranked", time.Now().UnixMilli())
Updates(map[string]interface{}{
"clan_ranked": clanRanked,
"date_clan_ranked": dateClanRanked,
})

return result.Error
if result.Error != nil {
return result.Error
}
return UpdateElasticSearchMapClanRanked(id, clanRanked, dateClanRanked)
}

func GetBundledMapMd5s() ([]string, error) {
Expand Down
Loading