Browse Source

fix-1311

tags/v1.22.1.2
ychao_1983 4 years ago
parent
commit
51836a5ddc
2 changed files with 25 additions and 10 deletions
  1. +2
    -2
      models/action.go
  2. +23
    -8
      services/socketwrap/clientManager.go

+ 2
- 2
models/action.go View File

@@ -346,11 +346,11 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
return actions, nil
}

func GetLast20PublicFeeds() ([]*Action, error) {
func GetLast20PublicFeeds(opTypes []int) ([]*Action, error) {
cond := builder.NewCond()
cond = cond.And(builder.Eq{"is_private": false})
cond = cond.And(builder.Eq{"is_deleted": false})
cond = cond.And(builder.In("op_type", opTypes))

actions := make([]*Action, 0, 20)



+ 23
- 8
services/socketwrap/clientManager.go View File

@@ -10,6 +10,8 @@ import (
"github.com/elliotchance/orderedmap"
)

var opTypes = []int{1, 2, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 22, 23}

type ClientsManager struct {
Clients *orderedmap.OrderedMap
Register chan *Client
@@ -47,13 +49,15 @@ func (h *ClientsManager) Run() {
close(client.Send)
}
case message := <-models.ActionChan:
LastActionsQueue.Push(message)
for _, client := range h.Clients.Keys() {
select {
case client.(*Client).Send <- message:
default:
close(client.(*Client).Send)
h.Clients.Delete(client)
if isInOpTypes(opTypes, message.OpType) {
LastActionsQueue.Push(message)
for _, client := range h.Clients.Keys() {
select {
case client.(*Client).Send <- message:
default:
close(client.(*Client).Send)
h.Clients.Delete(client)
}
}
}
case s := <-sig:
@@ -71,8 +75,19 @@ func (h *ClientsManager) Run() {
}
}

func isInOpTypes(types []int, opType models.ActionType) bool {
isFound := false
for _, value := range types {
if value == int(opType) {
isFound = true
break
}
}
return isFound
}

func initActionQueue() {
actions, err := models.GetLast20PublicFeeds()
actions, err := models.GetLast20PublicFeeds(opTypes)
if err == nil {
for i := len(actions) - 1; i >= 0; i-- {



Loading…
Cancel
Save