cache.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. package region
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "go-common/app/interface/main/app-show/model"
  8. "go-common/app/interface/main/app-show/model/bangumi"
  9. "go-common/app/interface/main/app-show/model/card"
  10. "go-common/app/interface/main/app-show/model/region"
  11. "go-common/app/interface/main/app-show/model/tag"
  12. "go-common/app/service/main/archive/api"
  13. resource "go-common/app/service/main/resource/model"
  14. "go-common/library/log"
  15. )
  16. var (
  17. // 番剧 动画,音乐,舞蹈,游戏,科技,娱乐,鬼畜,电影,时尚, 生活,国漫
  18. _tids = []int{13, 1, 3, 129, 4, 36, 5, 119, 23, 155, 160, 11, 167}
  19. )
  20. // loadBanner1 load banner cache.
  21. func (s *Service) loadBanner() {
  22. var (
  23. resbs = map[int8]map[int][]*resource.Banner{}
  24. )
  25. for plat, resIDStr := range _bannersPlat {
  26. mobiApp := model.MobiApp(plat)
  27. res, err := s.res.ResBanner(context.TODO(), plat, 515007, 0, resIDStr, "master", "", "", "", mobiApp, "", "", false)
  28. if err != nil || len(res) == 0 {
  29. log.Error("s.res.ResBanner is null or err(%v)", err)
  30. return
  31. }
  32. resbs[plat] = res
  33. }
  34. if len(resbs) > 0 {
  35. s.bannerCache = resbs
  36. }
  37. log.Info("loadBannerCahce success")
  38. }
  39. func (s *Service) loadbgmBanner() {
  40. bgmBanners := map[int8]map[int][]*bangumi.Banner{}
  41. for plat, b := range _bannersPGC {
  42. ridBanners := map[int][]*bangumi.Banner{}
  43. for rid, pgcID := range b {
  44. bBanner, err := s.bgm.Banners(context.TODO(), pgcID)
  45. if err != nil {
  46. log.Error("s.bgmdao.Banners is null or err(%v)", err)
  47. return
  48. }
  49. ridBanners[rid] = bBanner
  50. }
  51. bgmBanners[plat] = ridBanners
  52. }
  53. s.bannerBmgCache = bgmBanners
  54. }
  55. // loadRegionShow
  56. func (s *Service) loadShow() {
  57. // default use android regions TODO
  58. regionkey := fmt.Sprintf(_initRegionKey, model.PlatAndroid, _initlanguage)
  59. res := s.cachelist[regionkey]
  60. var (
  61. // region tmp
  62. showTmp = map[int][]*region.ShowItem{} // tmp hotCache
  63. showNTmp = map[int][]*region.ShowItem{} // tmp newCache
  64. showD = map[int][]*region.ShowItem{} // tmp dynamicCache
  65. sTmp = map[int]*region.Show{}
  66. // region tmp overseas
  67. showTmpOsea = map[int][]*region.ShowItem{} // tmp overseas hotCache
  68. showNTmpOsea = map[int][]*region.ShowItem{} // tmp overseas newCache
  69. showDOsea = map[int][]*region.ShowItem{} // tmp overseas dynamicCache
  70. sTmpOsea = map[int]*region.Show{}
  71. // aids
  72. showDynamicAids = map[int][]int64{}
  73. // new region feed
  74. regionFeedTmp = map[int]*region.Show{}
  75. regionFeedTmpOsea = map[int]*region.Show{}
  76. )
  77. for _, v := range res {
  78. if v.Reid == 0 {
  79. if v.Rid == 65537 || v.Rid == 65539 || v.Rid == 65541 || v.Rid == 65543 {
  80. continue
  81. }
  82. var (
  83. tmp, tmpOsea []*region.ShowItem
  84. aidsTmp []int64
  85. )
  86. tmp, tmpOsea = s.loadShowHot(v.Rid)
  87. showTmp[v.Rid], showTmpOsea[v.Rid] = s.upCache(tmp, tmpOsea, s.hotCache[v.Rid], s.hotOseaCache[v.Rid])
  88. tmp, tmpOsea = s.loadShowNewRpc(v.Rid)
  89. showNTmp[v.Rid], showNTmpOsea[v.Rid] = s.upCache(tmp, tmpOsea, s.newCache[v.Rid], s.newOseaCache[v.Rid])
  90. tmp, tmpOsea, aidsTmp = s.loadShowDynamic(v.Rid)
  91. showDynamicAids[v.Rid] = s.upAidsCache(aidsTmp, s.showDynamicAidsCache[v.Rid])
  92. showD[v.Rid], showDOsea[v.Rid] = s.upCache(tmp, tmpOsea, s.dynamicCache[v.Rid], s.dynamicOseaCache[v.Rid])
  93. sTmp[v.Rid] = s.mergeShow(showTmp[v.Rid], showNTmp[v.Rid], showD[v.Rid])
  94. // overseas
  95. sTmpOsea[v.Rid] = s.mergeShow(showTmpOsea[v.Rid], showNTmpOsea[v.Rid], showDOsea[v.Rid])
  96. // new region feed
  97. regionFeedTmp[v.Rid], _ = s.mergeChildShow(showTmp[v.Rid], showNTmp[v.Rid])
  98. regionFeedTmpOsea[v.Rid], _ = s.mergeChildShow(showTmpOsea[v.Rid], showNTmpOsea[v.Rid])
  99. }
  100. }
  101. s.showCache = sTmp
  102. s.hotCache = showTmp
  103. s.newCache = showNTmp
  104. s.dynamicCache = showD
  105. // overseas
  106. s.showOseaCache = sTmpOsea
  107. s.hotOseaCache = showTmpOsea
  108. s.newOseaCache = showNTmpOsea
  109. s.dynamicOseaCache = showDOsea
  110. // new region feed
  111. s.regionFeedCache = regionFeedTmp
  112. s.regionFeedOseaCache = regionFeedTmpOsea
  113. // aids
  114. s.showDynamicAidsCache = showDynamicAids
  115. }
  116. // loadShowChild
  117. func (s *Service) loadShowChild() {
  118. // default use android regions TODO
  119. regionkey := fmt.Sprintf(_initRegionKey, model.PlatAndroid, _initlanguage)
  120. res := s.cachelist[regionkey]
  121. var (
  122. scTmp = map[int]*region.Show{}
  123. showC = map[int][]*region.ShowItem{} // tmp childHotCache
  124. showCN = map[int][]*region.ShowItem{} // tmp childNewCache
  125. // region tmp overseas
  126. scTmpOsea = map[int]*region.Show{}
  127. showCOsea = map[int][]*region.ShowItem{} // tmp overseas childHotCache
  128. showCNOsea = map[int][]*region.ShowItem{} // tmp overseas childNewCache
  129. // aids
  130. showChildAids = map[int][]int64{}
  131. showNewAids = map[int][]int64{}
  132. )
  133. for _, v := range res {
  134. if v.Reid != 0 {
  135. var (
  136. tmp, tmpOsea []*region.ShowItem
  137. aidsTmp []int64
  138. )
  139. tmp, tmpOsea, aidsTmp = s.loadShowChileHot(v.Rid)
  140. showChildAids[v.Rid] = s.upAidsCache(aidsTmp, s.childHotAidsCache[v.Rid])
  141. showC[v.Rid], showCOsea[v.Rid] = s.upCache(tmp, tmpOsea, s.childHotCache[v.Rid], s.childHotOseaCache[v.Rid])
  142. tmp, tmpOsea, aidsTmp = s.loadShowChildNew(v.Rid)
  143. showNewAids[v.Rid] = s.upAidsCache(aidsTmp, s.childNewAidsCache[v.Rid])
  144. showCN[v.Rid], showCNOsea[v.Rid] = s.upCache(tmp, tmpOsea, s.childNewCache[v.Rid], s.childNewOseaCache[v.Rid])
  145. scTmp[v.Rid], showCN[v.Rid] = s.mergeChildShow(showC[v.Rid], showCN[v.Rid])
  146. // overseas
  147. scTmpOsea[v.Rid], showCNOsea[v.Rid] = s.mergeChildShow(showCOsea[v.Rid], showCNOsea[v.Rid])
  148. }
  149. }
  150. s.childShowCache = scTmp
  151. s.childHotCache = showC
  152. s.childNewCache = showCN
  153. // overseas
  154. s.childShowOseaCache = scTmpOsea
  155. s.childHotOseaCache = showCOsea
  156. s.childNewOseaCache = showCNOsea
  157. // region child aids
  158. s.childHotAidsCache = showChildAids
  159. s.childNewAidsCache = showNewAids
  160. }
  161. func (s *Service) loadShowChildTagsInfo() {
  162. // default use android regions TODO
  163. regionkey := fmt.Sprintf(_initRegionKey, model.PlatAndroid, _initlanguage)
  164. res := s.cachelist[regionkey]
  165. reslist := s.regionListCache[regionkey]
  166. var (
  167. // tag tmp
  168. tagsRegionTmp = map[int][]*region.SimilarTag{} // region tags
  169. tagsTmp = map[string]string{} // tagid cache
  170. )
  171. for _, v := range res {
  172. if v.Reid != 0 {
  173. //tag
  174. var rTmp *region.Region
  175. if r, ok := reslist[v.Reid]; ok {
  176. rTmp = r
  177. }
  178. if tids := s.loadShowChildTagIDs(v.Rid); len(tids) > 0 {
  179. for _, tag := range tids {
  180. tagInfo := &region.SimilarTag{
  181. TagId: int(tag.Tid),
  182. TagName: tag.Name,
  183. Rid: v.Rid,
  184. Rname: v.Name,
  185. }
  186. if rTmp != nil {
  187. tagInfo.Reid = rTmp.Rid
  188. tagInfo.Rename = rTmp.Name
  189. }
  190. //tags info
  191. tagsRegionTmp[v.Rid] = append(tagsRegionTmp[v.Rid], tagInfo)
  192. key := fmt.Sprintf(_initRegionTagKey, v.Rid, tag.Tid)
  193. tagsTmp[key] = tag.Name
  194. }
  195. }
  196. }
  197. }
  198. // region child aids
  199. s.regionTagCache = tagsRegionTmp
  200. s.tagsCache = tagsTmp
  201. }
  202. // loadShowHot
  203. func (s *Service) loadShowHot(rid int) (resData, resOseaData []*region.ShowItem) {
  204. res, err := s.rcmmnd.RegionHots(context.TODO(), rid)
  205. if err != nil {
  206. log.Error("s.rcmmnd.RegionHot(%d) error(%v)", rid, err)
  207. return
  208. }
  209. if len(res) > 8 {
  210. res = res[:8]
  211. }
  212. resData, resOseaData = s.fromAids(context.TODO(), res, false, 0)
  213. log.Info("loadShowHot(%d) success", rid)
  214. return
  215. }
  216. // loadShowNewRpc
  217. func (s *Service) loadShowNewRpc(rid int) (resData, resOseaData []*region.ShowItem) {
  218. arcs, err := s.arc.RankTopArcs(context.TODO(), rid, 1, 20)
  219. if err != nil {
  220. log.Error("s.arc.RankTopArcs(%d) error(%v)", rid, err)
  221. return
  222. }
  223. if len(arcs) > 20 {
  224. arcs = arcs[:20]
  225. }
  226. resData, resOseaData = s.fromArchivesPB(arcs)
  227. log.Info("loadShowNewRpc(%d) success", rid)
  228. return
  229. }
  230. // loadShowDynamic
  231. func (s *Service) loadShowDynamic(rid int) (resData, resOseaData []*region.ShowItem, arcAids []int64) {
  232. var (
  233. err error
  234. arcs []*api.Arc
  235. )
  236. arcs, arcAids, err = s.dyn.RegionDynamic(context.TODO(), rid, 1, 100)
  237. if err != nil || len(arcs) < 20 {
  238. log.Error("s.rcmmnd.RegionDynamic(%d) error(%v)", rid, err)
  239. return
  240. }
  241. resData, resOseaData = s.fromArchivesPB(arcs)
  242. log.Info("loadShowRPCDynamic(%d) success", rid)
  243. return
  244. }
  245. // loadShowChileHot
  246. func (s *Service) loadShowChileHot(rid int) (resData, resOseaData []*region.ShowItem, arcAids []int64) {
  247. var err error
  248. arcAids, err = s.rcmmnd.RegionChildHots(context.TODO(), rid)
  249. if err != nil || len(arcAids) < 4 {
  250. log.Error("s.rcmmnd.RegionChildHots(%d) error(%v)", rid, err)
  251. return
  252. }
  253. resData, resOseaData = s.fromAids(context.TODO(), arcAids, false, 0)
  254. log.Info("loadShowChileHot(%d) success", rid)
  255. return
  256. }
  257. // loadShowChildNew
  258. func (s *Service) loadShowChildNew(rid int) (resData, resOseaData []*region.ShowItem, arcAids []int64) {
  259. var (
  260. err error
  261. arcs []*api.Arc
  262. )
  263. arcs, arcAids, err = s.arc.RanksArcs(context.TODO(), rid, 1, 300)
  264. if err != nil || len(arcAids) < 20 {
  265. log.Error("s.arc.RanksArc(%d) error(%v)", rid, err)
  266. return
  267. }
  268. resData, resOseaData = s.fromArchivesPB(arcs)
  269. log.Info("loadShowChildNew(%d) success", rid)
  270. return
  271. }
  272. // loadShowChildTagIDs
  273. func (s *Service) loadShowChildTagIDs(rid int) (tags []*tag.Tag) {
  274. tags, err := s.tag.TagHotsId(context.TODO(), rid, time.Now())
  275. if err != nil || len(tags) == 0 {
  276. log.Error("s.tag.loadShowChildTagIDs(%d) error(%v)", rid, err)
  277. return
  278. }
  279. return
  280. }
  281. // loadRankRegionCache
  282. func (s *Service) loadRankRegionCache() {
  283. var (
  284. tmp = map[int][]*region.ShowItem{}
  285. tmpOsea = map[int][]*region.ShowItem{}
  286. )
  287. for _, rid := range _tids {
  288. aids, others, scores, err := s.rcmmnd.RankAppRegion(context.TODO(), rid)
  289. if err != nil {
  290. log.Error("s.rcmmnd.RankAppRegion rid (%v) error(%v)", rid, err)
  291. return
  292. }
  293. tRank, tOseaRank := s.fromRankAids(context.TODO(), aids, others, scores)
  294. tmp[rid] = tRank
  295. tmpOsea[rid] = tOseaRank
  296. }
  297. if len(tmp) > 0 {
  298. s.rankCache = tmp
  299. }
  300. if len(tmpOsea) > 0 {
  301. s.rankOseaCache = tmpOsea
  302. }
  303. }
  304. // loadRegionListCache
  305. func (s *Service) loadRegionListCache() {
  306. res, err := s.dao.RegionPlat(context.TODO())
  307. if err != nil {
  308. log.Error("s.dao.RegionPlat error(%v)", err)
  309. return
  310. }
  311. tmpRegion := map[int]*region.Region{}
  312. tmp := map[int]*region.Region{}
  313. for _, v := range res {
  314. // region list map
  315. tmpRegion[v.Rid] = v
  316. }
  317. for _, r := range res {
  318. if r.Reid != 0 {
  319. if rerg, ok := tmpRegion[r.Reid]; ok {
  320. tmp[r.Rid] = rerg
  321. }
  322. }
  323. }
  324. s.reRegionCache = tmp
  325. }
  326. func (s *Service) loadColumnListCache(now time.Time) {
  327. var (
  328. tmpChild = map[int]*card.ColumnList{}
  329. )
  330. columns, err := s.cdao.ColumnList(context.TODO(), now)
  331. if err != nil {
  332. log.Error("s.cdao.ColumnList error(%v)", err)
  333. return
  334. }
  335. for _, column := range columns {
  336. tmpChild[column.Cid] = column
  337. }
  338. s.columnListCache = tmpChild
  339. }
  340. // loadCardCache load all card cache
  341. func (s *Service) loadCardCache(now time.Time) {
  342. hdm, err := s.cdao.PosRecs(context.TODO(), now)
  343. if err != nil {
  344. log.Error("s.cdao.PosRecs error(%v)", err)
  345. return
  346. }
  347. itm, aids, err := s.cdao.RecContents(context.TODO(), now)
  348. if err != nil {
  349. log.Error("s.cdao.RecContents error(%v)", err)
  350. return
  351. }
  352. tmpItem := map[int]map[int64]*region.ShowItem{}
  353. for recid, aid := range aids {
  354. tmpItem[recid] = s.fromCardAids(context.TODO(), aid)
  355. }
  356. tmp := s.mergeCard(context.TODO(), hdm, itm, tmpItem, now)
  357. s.cardCache = tmp
  358. }
  359. func (s *Service) mergeCard(c context.Context, hdm map[int8]map[int][]*card.Card, itm map[int][]*card.Content, tmpItems map[int]map[int64]*region.ShowItem, now time.Time) (res map[string][]*region.Head) {
  360. // default use android regions TODO
  361. var (
  362. _topic = 1
  363. _activity = 0
  364. regionkey = fmt.Sprintf(_initRegionKey, model.PlatAndroid, _initlanguage)
  365. regionList = s.cachelist[regionkey]
  366. )
  367. res = map[string][]*region.Head{}
  368. for _, v := range regionList {
  369. if v.Reid != 0 {
  370. continue
  371. }
  372. for plat, phds := range hdm {
  373. hds, ok := phds[v.Rid]
  374. if !ok {
  375. continue
  376. }
  377. for _, hd := range hds {
  378. key := fmt.Sprintf(_initCardKey, plat, v.Rid)
  379. var (
  380. sis []*region.ShowItem
  381. )
  382. its, ok := itm[hd.ID]
  383. if !ok {
  384. its = []*card.Content{}
  385. }
  386. tmpItem, ok := tmpItems[hd.ID]
  387. if !ok {
  388. tmpItem = map[int64]*region.ShowItem{}
  389. }
  390. // 1 daily 2 topic 3 activity 4 rank 5 polymeric_card
  391. switch hd.Type {
  392. case 1:
  393. for _, ci := range its {
  394. si := s.fillCardItem(ci, tmpItem)
  395. if si.Title != "" {
  396. sis = append(sis, si)
  397. }
  398. }
  399. case 2:
  400. if topicID, err := strconv.ParseInt(hd.Rvalue, 10, 64); err == nil {
  401. if actm, err := s.act.Activitys(c, []int64{topicID}, _topic, ""); err != nil {
  402. log.Error("s.act.Activitys topicID error (%v)", topicID, err)
  403. } else {
  404. if act, ok := actm[topicID]; ok && act.H5Cover != "" && act.H5URL != "" {
  405. si := &region.ShowItem{}
  406. si.FromTopic(act)
  407. sis = []*region.ShowItem{si}
  408. }
  409. }
  410. }
  411. case 3:
  412. if topicID, err := strconv.ParseInt(hd.Rvalue, 10, 64); err == nil {
  413. if actm, err := s.act.Activitys(c, []int64{topicID}, _activity, ""); err != nil {
  414. log.Error("s.act.Activitys topicID error (%v)", topicID, err)
  415. } else {
  416. if act, ok := actm[topicID]; ok && act.H5Cover != "" && act.H5URL != "" {
  417. si := &region.ShowItem{}
  418. si.FromActivity(act, now)
  419. sis = []*region.ShowItem{si}
  420. }
  421. }
  422. }
  423. case 4:
  424. if tmpRank, ok := s.rankCache[v.Rid]; ok {
  425. if len(tmpRank) > 3 {
  426. sis = tmpRank[:3]
  427. } else {
  428. sis = tmpRank
  429. }
  430. }
  431. case 5, 6, 8:
  432. for _, ci := range its {
  433. si := s.fillCardItem(ci, tmpItem)
  434. if si.Title != "" {
  435. sis = append(sis, si)
  436. }
  437. }
  438. case 7:
  439. si := &region.ShowItem{
  440. Title: hd.Title,
  441. Cover: hd.Cover,
  442. Desc: hd.Desc,
  443. Goto: hd.Goto,
  444. Param: hd.Param,
  445. }
  446. if hd.Goto == model.GotoColumnStage {
  447. paramInt, _ := strconv.Atoi(hd.Param)
  448. if c, ok := s.columnListCache[paramInt]; ok {
  449. cidStr := strconv.Itoa(c.Ceid)
  450. si.URI = model.FillURICategory(hd.Goto, cidStr, hd.Param)
  451. }
  452. } else {
  453. si.URI = hd.URi
  454. }
  455. sis = append(sis, si)
  456. default:
  457. continue
  458. }
  459. if len(sis) == 0 {
  460. continue
  461. }
  462. sw := &region.Head{
  463. CardID: hd.ID,
  464. Title: hd.Title,
  465. Type: hd.TypeStr,
  466. Build: hd.Build,
  467. Condition: hd.Condition,
  468. Plat: hd.Plat,
  469. }
  470. if hd.Cover != "" {
  471. sw.Cover = hd.Cover
  472. }
  473. switch sw.Type {
  474. case model.GotoDaily:
  475. sw.Date = now.Unix()
  476. sw.Param = hd.Rvalue
  477. sw.URI = hd.URi
  478. sw.Goto = hd.Goto
  479. case model.GotoCard:
  480. sw.URI = hd.URi
  481. sw.Goto = hd.Goto
  482. sw.Param = hd.Param
  483. case model.GotoRank:
  484. sw.Param = strconv.Itoa(v.Rid)
  485. case model.GotoTopic, model.GotoActivity:
  486. if sw.Title == "" {
  487. if len(sis) > 0 {
  488. sw.Title = sis[0].Title
  489. }
  490. }
  491. case model.GotoVeidoCard:
  492. sw.Param = hd.Param
  493. if hd.Goto == model.GotoColumnStage {
  494. paramInt, _ := strconv.Atoi(hd.Param)
  495. if c, ok := s.columnListCache[paramInt]; ok {
  496. cidStr := strconv.Itoa(c.Ceid)
  497. sw.URI = model.FillURICategory(hd.Goto, cidStr, hd.Param)
  498. }
  499. sw.Goto = model.GotoColumn
  500. } else {
  501. sw.Goto = hd.Goto
  502. sw.URI = hd.URi
  503. }
  504. if sisLen := len(sis); sisLen > 1 {
  505. if sisLen%2 != 0 {
  506. sis = sis[:sisLen-1]
  507. }
  508. } else {
  509. continue
  510. }
  511. case model.GotoSpecialCard:
  512. sw.Cover = ""
  513. case model.GotoTagCard:
  514. if hd.TagID > 0 {
  515. var tagIDInt int64
  516. sw.Title, tagIDInt = s.fromTagIDByName(c, hd.TagID, now)
  517. sw.Param = strconv.FormatInt(tagIDInt, 10)
  518. sw.Goto = model.GotoTagID
  519. }
  520. }
  521. sw.Body = sis
  522. res[key] = append(res[key], sw)
  523. }
  524. }
  525. }
  526. return
  527. }
  528. // fillCardItem
  529. func (s *Service) fillCardItem(csi *card.Content, tsi map[int64]*region.ShowItem) (si *region.ShowItem) {
  530. si = &region.ShowItem{}
  531. switch csi.Type {
  532. case model.CardGotoAv:
  533. si.Goto = model.GotoAv
  534. si.Param = csi.Value
  535. }
  536. si.URI = model.FillURI(si.Goto, si.Param, nil)
  537. if si.Goto == model.GotoAv {
  538. aid, err := strconv.ParseInt(si.Param, 10, 64)
  539. if err != nil {
  540. log.Error("strconv.ParseInt(%s) error(%v)", si.Param, err)
  541. } else {
  542. if it, ok := tsi[aid]; ok {
  543. si = it
  544. if csi.Title != "" {
  545. si.Title = csi.Title
  546. }
  547. } else {
  548. si = &region.ShowItem{}
  549. }
  550. }
  551. }
  552. return
  553. }
  554. // fromTagIDByName from tag_id by tag_name
  555. func (s *Service) fromTagIDByName(ctx context.Context, tagID int, now time.Time) (tagName string, tagIDInt int64) {
  556. tag, err := s.tag.TagInfo(ctx, 0, tagID, now)
  557. if err != nil {
  558. log.Error("s.tag.TagInfo(%d) error(%v)", tagID, err)
  559. return
  560. }
  561. tagName = tag.Name
  562. tagIDInt = tag.Tid
  563. return
  564. }
  565. // upCahce update cache
  566. func (s *Service) upCache(new, newOsea, old, oldOsea []*region.ShowItem) (res, resOsea []*region.ShowItem) {
  567. if len(new) > 0 {
  568. res = new
  569. } else {
  570. res = old
  571. }
  572. if len(newOsea) > 0 {
  573. resOsea = newOsea
  574. } else {
  575. resOsea = oldOsea
  576. }
  577. return
  578. }
  579. // upAidsCache update aids cache
  580. func (s *Service) upAidsCache(new, old []int64) (aids []int64) {
  581. if len(new) > 0 {
  582. aids = new
  583. } else {
  584. aids = old
  585. }
  586. return
  587. }