增加更新时间索引

pull/23/head
taoshihan1991 4 years ago
parent 2fcbe6e2fd
commit 477fe9eca2

@ -34,7 +34,8 @@ CREATE TABLE `visitor` (
`extra` varchar(2048) NOT NULL DEFAULT '', `extra` varchar(2048) NOT NULL DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `visitor_id` (`visitor_id`), UNIQUE KEY `visitor_id` (`visitor_id`),
KEY `to_id` (`to_id`) KEY `to_id` (`to_id`),
KEY `idx_update` (`updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8| ) ENGINE=InnoDB DEFAULT CHARSET=utf8|
DROP TABLE IF EXISTS `message`| DROP TABLE IF EXISTS `message`|

@ -1,6 +1,8 @@
package models package models
import "time" import (
"time"
)
type Visitor struct { type Visitor struct {
Model Model
@ -54,11 +56,13 @@ func FindVisitors(page uint, pagesize uint) []Visitor {
} }
func FindVisitorsByKefuId(page uint, pagesize uint, kefuId string) []Visitor { func FindVisitorsByKefuId(page uint, pagesize uint, kefuId string) []Visitor {
offset := (page - 1) * pagesize offset := (page - 1) * pagesize
if offset < 0 { if offset <= 0 {
offset = 0 offset = 0
} }
var visitors []Visitor var visitors []Visitor
DB.Where("to_id=?", kefuId).Offset(offset).Limit(pagesize).Order("status desc, updated_at desc").Find(&visitors) //sql := fmt.Sprintf("select * from visitor where id>=(select id from visitor where to_id='%s' order by updated_at desc limit %d,1) and to_id='%s' order by updated_at desc limit %d ", kefuId, offset, kefuId, pagesize)
//DB.Raw(sql).Scan(&visitors)
DB.Where("to_id=?", kefuId).Offset(offset).Limit(pagesize).Order("updated_at desc").Find(&visitors)
return visitors return visitors
} }
func FindVisitorsOnline() []Visitor { func FindVisitorsOnline() []Visitor {

Loading…
Cancel
Save