| 221 | } |
| 222 | |
| 223 | func UpdateAdsCache() { |
| 224 | var ( |
| 225 | ads []AdsCont |
| 226 | cache sync.Map |
| 227 | data = make(map[int][]AdsCont) |
| 228 | ) |
| 229 | now := time.Now().Unix() |
| 230 | orm.NewOrm().QueryTable(&AdsCont{}).Filter("status", 1).Filter("start__lt", now).Filter("end__gt", now).All(&ads) |
| 231 | for _, item := range ads { |
| 232 | data[item.Pid] = append(data[item.Pid], item) |
| 233 | } |
| 234 | if beego.AppConfig.String("runmode") == "dev" { |
| 235 | beego.Info(" =============== update ads cache =============== ") |
| 236 | } |
| 237 | for pid, arr := range data { |
| 238 | cache.Store(pid, arr) |
| 239 | } |
| 240 | adsCache = cache |
| 241 | } |
| 242 | |
| 243 | func (m *AdsCont) GetPositions() []AdsPosition { |
| 244 | var positions []AdsPosition |