Skip to content

Commit

Permalink
Sync bug fix + Composite Id Rework to avoid Storm Bug with string com…
Browse files Browse the repository at this point in the history
…posite id
  • Loading branch information
jypelle committed Oct 24, 2019
1 parent 3e72276 commit e63583d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 58 deletions.
8 changes: 4 additions & 4 deletions restApiV1/artist.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package restApiV1
// Artist

type Artist struct {
Id string `json:"id" storm:"id"`
Id string `json:"id"`
CreationTs int64 `json:"creationTs"`
UpdateTs int64 `json:"updateTs" storm:"index"`
ArtistMeta `storm:"inline"`
UpdateTs int64 `json:"updateTs"`
ArtistMeta
}

type ArtistMeta struct {
Name string `json:"name" storm:"index"`
Name string `json:"name"`
}
11 changes: 4 additions & 7 deletions srv/entity/artist.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ type ArtistSongId struct {
}

type ArtistSongEntity struct {
Id ArtistSongId `storm:"id"`
ArtistId string `storm:"index"`
SongId string `storm:"index"`
Id string `storm:"id"`
ArtistId string `storm:"index"`
SongId string `storm:"index"`
}

func NewArtistSongEntity(artistId string, songId string) *ArtistSongEntity {
return &ArtistSongEntity{
Id: ArtistSongId{
ArtistId: artistId,
SongId: songId,
},
Id: artistId + ":" + songId,
ArtistId: artistId,
SongId: songId,
}
Expand Down
31 changes: 15 additions & 16 deletions srv/entity/favoritePlaylist.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,50 @@ import (
)

type FavoritePlaylistEntity struct {
Id restApiV1.FavoritePlaylistId `storm:"id"`
UpdateTs int64 `storm:"index"`
UserId string `storm:"index"`
PlaylistId string `storm:"index"`
Id string `storm:"id"`
UpdateTs int64 `storm:"index"`
UserId string `storm:"index"`
PlaylistId string `storm:"index"`
}

func NewFavoritePlaylistEntity(userId string, playlistId string) *FavoritePlaylistEntity {
now := time.Now().UnixNano()

return &FavoritePlaylistEntity{
Id: restApiV1.FavoritePlaylistId{
UserId: userId,
PlaylistId: playlistId,
},
Id: userId + ":" + playlistId,
UpdateTs: now,
UserId: userId,
PlaylistId: playlistId,
}
}

func (e *FavoritePlaylistEntity) Fill(s *restApiV1.FavoritePlaylist) {
s.Id = e.Id
s.Id = restApiV1.FavoritePlaylistId{UserId: e.UserId, PlaylistId: e.PlaylistId}
s.UpdateTs = e.UpdateTs
}

func (e *FavoritePlaylistEntity) LoadMeta(s *restApiV1.FavoritePlaylistMeta) {
if s != nil {
e.Id = s.Id
e.Id = s.Id.UserId + ":" + s.Id.PlaylistId
e.UserId = s.Id.UserId
e.PlaylistId = s.Id.PlaylistId
}
}

type DeletedFavoritePlaylistEntity struct {
Id restApiV1.FavoritePlaylistId `storm:"id"`
DeleteTs int64 `storm:"index"`
UserId string `storm:"index"`
Id string `storm:"id"`
DeleteTs int64 `storm:"index"`
UserId string `storm:"index"`
PlaylistId string `storm:"index"`
}

func NewDeletedFavoritePlaylistEntity(favoritePlaylistId restApiV1.FavoritePlaylistId) *DeletedFavoritePlaylistEntity {
now := time.Now().UnixNano()

return &DeletedFavoritePlaylistEntity{
Id: favoritePlaylistId,
DeleteTs: now,
UserId: favoritePlaylistId.UserId,
Id: favoritePlaylistId.UserId + ":" + favoritePlaylistId.PlaylistId,
DeleteTs: now,
UserId: favoritePlaylistId.UserId,
PlaylistId: favoritePlaylistId.PlaylistId,
}
}
31 changes: 12 additions & 19 deletions srv/entity/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,29 @@ type PlaylistSongId struct {
}

type PlaylistSongEntity struct {
Id PlaylistSongId `storm:"id"`
SongId string `storm:"index"`
Id string `storm:"id"`
PlaylistId string `storm:"index"`
SongId string `storm:"index"`
}

func NewPlaylistSongEntity(playlistId string, songId string) *PlaylistSongEntity {
return &PlaylistSongEntity{
Id: PlaylistSongId{
PlaylistId: playlistId,
SongId: songId,
},
SongId: songId,
Id: playlistId + ":" + songId,
PlaylistId: playlistId,
SongId: songId,
}
}

type OwnedUserPlaylistId struct {
UserId string
PlaylistId string
}

type OwnedUserPlaylistEntity struct {
Id OwnedUserPlaylistId `storm:"id"`
UserId string `storm:"index"`
Id string `storm:"id"`
UserId string `storm:"index"`
PlaylistId string `storm:"index"`
}

func NewOwnedUserPlaylistEntity(userId string, playlistId string) *OwnedUserPlaylistEntity {
return &OwnedUserPlaylistEntity{
Id: OwnedUserPlaylistId{
UserId: userId,
PlaylistId: playlistId,
},
UserId: userId,
Id: userId + playlistId,
UserId: userId,
PlaylistId: playlistId,
}
}
12 changes: 6 additions & 6 deletions srv/svc/favoritePlaylist.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Service) CreateFavoritePlaylist(externalTrn storm.Node, favoritePlaylis

var favoritePlaylistEntity entity.FavoritePlaylistEntity

e = txn.One("Id", favoritePlaylistMeta.Id, &favoritePlaylistEntity)
e = txn.One("Id", favoritePlaylistMeta.Id.UserId+":"+favoritePlaylistMeta.Id.PlaylistId, &favoritePlaylistEntity)
if e != nil && e != storm.ErrNotFound {
return nil, e
}
Expand All @@ -116,7 +116,7 @@ func (s *Service) CreateFavoritePlaylist(externalTrn storm.Node, favoritePlaylis

// if previously deletedFavoritePlaylist exists
var deletedFavoritePlaylistEntity entity.DeletedFavoritePlaylistEntity
e = txn.One("Id", favoritePlaylistMeta.Id, &deletedFavoritePlaylistEntity)
e = txn.One("Id", favoritePlaylistMeta.Id.UserId+":"+favoritePlaylistMeta.Id.PlaylistId, &deletedFavoritePlaylistEntity)
if e != nil && e != storm.ErrNotFound {
return nil, e
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func (s *Service) DeleteFavoritePlaylist(externalTrn storm.Node, favoritePlaylis
}

var favoritePlaylistEntity entity.FavoritePlaylistEntity
e = txn.One("Id", favoritePlaylistId, &favoritePlaylistEntity)
e = txn.One("Id", favoritePlaylistId.UserId+":"+favoritePlaylistId.PlaylistId, &favoritePlaylistEntity)
if e != nil {
return nil, e
}
Expand All @@ -167,7 +167,7 @@ func (s *Service) DeleteFavoritePlaylist(externalTrn storm.Node, favoritePlaylis
}

// Archive favoritePlaylistId
e = txn.Save(entity.NewDeletedFavoritePlaylistEntity(favoritePlaylistEntity.Id))
e = txn.Save(entity.NewDeletedFavoritePlaylistEntity(favoritePlaylistId))
if e != nil {
return nil, e
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func (s *Service) GetDeletedFavoritePlaylistIds(externalTrn storm.Node, fromTs i
}

for _, deletedFavoritePlaylistEntity := range deletedFavoritePlaylistEntities {
favoritePlaylistIds = append(favoritePlaylistIds, deletedFavoritePlaylistEntity.Id)
favoritePlaylistIds = append(favoritePlaylistIds, restApiV1.FavoritePlaylistId{UserId: deletedFavoritePlaylistEntity.UserId, PlaylistId: deletedFavoritePlaylistEntity.PlaylistId})
}

return favoritePlaylistIds, nil
Expand Down Expand Up @@ -237,7 +237,7 @@ func (s *Service) GetDeletedUserFavoritePlaylistIds(externalTrn storm.Node, from
}

for _, deletedFavoritePlaylistEntity := range deletedFavoritePlaylistEntities {
playlistIds = append(playlistIds, deletedFavoritePlaylistEntity.Id.PlaylistId)
playlistIds = append(playlistIds, deletedFavoritePlaylistEntity.PlaylistId)
}

return playlistIds, nil
Expand Down
6 changes: 3 additions & 3 deletions srv/svc/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (s *Service) DeletePlaylist(externalTrn storm.Node, playlistId string) (*re
return nil, e
}
for _, favoritePlaylistEntity := range favoritePlaylistEntities {
s.DeleteFavoritePlaylist(txn, favoritePlaylistEntity.Id)
s.DeleteFavoritePlaylist(txn, restApiV1.FavoritePlaylistId{UserId: favoritePlaylistEntity.UserId, PlaylistId: favoritePlaylistEntity.PlaylistId})
}

// Delete ower link
Expand Down Expand Up @@ -494,7 +494,7 @@ func (s *Service) GetPlaylistIdsFromSongId(externalTrn storm.Node, songId string
}

for _, playlistSongEntity := range playlistSongEntities {
playlistIds = append(playlistIds, playlistSongEntity.Id.PlaylistId)
playlistIds = append(playlistIds, playlistSongEntity.PlaylistId)
}

return playlistIds, nil
Expand Down Expand Up @@ -525,7 +525,7 @@ func (s *Service) GetPlaylistIdsFromOwnerUserId(externalTrn storm.Node, ownerUse
}

for _, ownedUserPlaylistEntity := range ownedUserPlaylistEntities {
playlistIds = append(playlistIds, ownedUserPlaylistEntity.Id.PlaylistId)
playlistIds = append(playlistIds, ownedUserPlaylistEntity.PlaylistId)
}

return playlistIds, nil
Expand Down
4 changes: 2 additions & 2 deletions srv/svc/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (s *Service) ReadSyncReport(fromTs int64) (*restApiV1.SyncReport, error) {

var err error
var txn storm.Node
txn, err = s.Db.Begin(false)
txn, err = s.Db.Begin(true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *Service) ReadFileSyncReport(fromTs int64, userId string) (*restApiV1.Fi
var err error

var txn storm.Node
txn, err = s.Db.Begin(false)
txn, err = s.Db.Begin(true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "strconv"
var (
MajorVersionNumber int = 0
MinorVersionNumber int = 1
PatchVersionNumber int = 0
PatchVersionNumber int = 1
)

func Version() string {
Expand Down

0 comments on commit e63583d

Please sign in to comment.