Skip to content

Commit

Permalink
remove generated id and timestamp from persisted messages
Browse files Browse the repository at this point in the history
  • Loading branch information
felipejfc committed Jul 20, 2016
1 parent 2ce9046 commit 13557c3
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions modules/plugins_persistence_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ package modules
import (
"fmt"
"reflect"
"time"

"github.com/layeh/gopher-luar"
"github.com/satori/go.uuid"
"github.com/topfreegames/mqttbot/es"
"github.com/topfreegames/mqttbot/logger"
"github.com/yuin/gopher-lua"
"gopkg.in/topfreegames/elastic.v2"
)

type Message struct {
Id string `json:"id"`
Timestamp int32 `json:"timestamp"`
Payload string `json:"payload"`
Topic string `json:"topic"`
Payload string `json:"payload"`
Topic string `json:"topic"`
}

var esclient *elastic.Client
Expand Down Expand Up @@ -45,8 +41,6 @@ func IndexMessage(L *lua.LState) int {
message := Message{}
message.Payload = payload.String()
message.Topic = topic.String()
message.Timestamp = int32(time.Now().Unix())
message.Id = uuid.NewV4().String()
if _, err := esclient.Index().Index("chat").Type("message").BodyJson(message).Do(); err != nil {
L.Push(lua.LString(fmt.Sprintf("%s", err)))
L.Push(L.ToNumber(1))
Expand All @@ -67,7 +61,7 @@ func QueryMessages(L *lua.LState) int {
int(lua.LVAsNumber(limit)), topic.String(), int(lua.LVAsNumber(start))))
termQuery := elastic.NewQueryStringQuery(fmt.Sprintf("topic:\"%s\"", topic.String()))
searchResults, err := esclient.Search().Index("chat").Query(termQuery).
Sort("timestamp", false).From(int(lua.LVAsNumber(start))).
Sort("payload.timestamp", false).From(int(lua.LVAsNumber(start))).
Size(int(lua.LVAsNumber(limit))).Do()
if err != nil {
L.Push(lua.LString(fmt.Sprintf("%s", err)))
Expand Down

0 comments on commit 13557c3

Please sign in to comment.