@@ -2,8 +2,8 @@ package api
22
33import (
44"bytes"
5+ "encoding/binary"
56"encoding/json"
6- "strconv"
77
88"github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/boltdb/bolt"
99)
@@ -31,7 +31,7 @@ func (s *BoltStore) GetEpisodesByCast(castid uint64) []Episode {
3131s .db .View (func (tx * bolt.Tx )error {
3232b := tx .Bucket (boltBucketEpisodes )
3333c := tx .Bucket (boltBucketEpisodeCastIDIndex ).Cursor ()
34- prefix := [] byte ( strconv . FormatUint ( castid , 10 ) )
34+ prefix := uint64Bytes ( castid )
3535
3636for key ,id := c .Seek (prefix );bytes .HasPrefix (key ,prefix );key ,id = c .Next () {
3737v := b .Get (id )
@@ -52,9 +52,9 @@ func (s *BoltStore) GetEpisodesSince(ts int64) []Episode {
5252s .db .View (func (tx * bolt.Tx )error {
5353b := tx .Bucket (boltBucketEpisodes )
5454c := tx .Bucket (boltBucketEpisodeCrawlTSIndex ).Cursor ()
55- prefix := [] byte ( strconv . FormatInt (ts + 1 , 10 ) )
55+ min := uint64Bytes ( uint64 (ts ) + 1 )
5656
57- for _ ,id := c .Seek (prefix );id != nil ;_ ,id = c .Next () {
57+ for _ ,id := c .Seek (min );id != nil ;_ ,id = c .Next () {
5858v := b .Get (id )
5959episode := Episode {}
6060json .Unmarshal (v ,& episode )
@@ -113,16 +113,19 @@ func (s *BoltStore) saveEpisode(tx *bolt.Tx, ep *Episode) error {
113113return err
114114}
115115
116- epID := strconv .FormatUint (ep .ID ,10 )
117- idxID := []byte (strconv .FormatUint (ep .CastID ,10 )+ ":" + epID )
116+ idxID := make ([]byte ,16 )
117+ binary .BigEndian .PutUint64 (idxID [:8 ],ep .CastID )
118+ binary .BigEndian .PutUint64 (idxID [8 :],ep .ID )
118119castIndex := tx .Bucket (boltBucketEpisodeCastIDIndex )
119120err = castIndex .Put (idxID ,id )
120121if err != nil {
121122return err
122123}
123124
124125crawlTSIndex := tx .Bucket (boltBucketEpisodeCrawlTSIndex )
125- idxID = []byte (strconv .FormatInt (ep .CrawlTS ,10 )+ ":" + epID )
126+ idxID = make ([]byte ,16 )
127+ binary .BigEndian .PutUint64 (idxID [:8 ],uint64 (ep .CrawlTS ))
128+ binary .BigEndian .PutUint64 (idxID [8 :],ep .ID )
126129err = crawlTSIndex .Put (idxID ,id )
127130if err != nil {
128131return err