Documentation ¶
Index ¶
- Constants
- Variables
- func NewAccessTokenDAO(session api.DbSession) api.AccessTokenDAO
- func NewEventDAO(session api.DbSession) api.EventDAO
- func NewEventHistoryDAO(session api.DbSession) api.EventHistoryDAO
- func NewFriendDAO(session api.DbSession) api.FriendDAO
- func NewFriendRequestDAO(session api.DbSession) api.FriendRequestDAO
- func NewLogDAO(session api.DbSession) api.LogDAO
- func NewSettingsDAO(session api.DbSession) api.SettingsDAO
- func NewThumbnailDAO(session api.DbSession) api.ThumbnailDAO
- func NewTimeLineDAO(session api.DbSession) api.EventTimeLineDAO
- func NewUserDAO(session api.DbSession) api.UserDAO
- type AccessTokenDAO
- type EventDAO
- func (d *EventDAO) DeleteAll() error
- func (d *EventDAO) Insert(event *api.EventDTO) error
- func (d *EventDAO) InsertParticipant(p *api.ParticipantDTO) error
- func (de *EventDAO) LoadEventPicture(event_id int64) (*api.PictureDTO, error)
- func (d *EventDAO) LoadEvents(event_ids ...int64) ([]*api.EventDTO, error)
- func (d *EventDAO) LoadParticipant(participantID int64, eventID int64) (*api.ParticipantDTO, error)
- func (d *EventDAO) RangeAll(f func(*api.EventDTO) error) error
- func (d *EventDAO) RangeEvents(f func(*api.EventDTO) error, event_ids ...int64) error
- func (d *EventDAO) Replace(oldEvent *api.EventDTO, newEvent *api.EventDTO) error
- func (dao *EventDAO) SetEventPicture(event_id int64, picture *api.PictureDTO) error
- type EventHistoryDAO
- func (d *EventHistoryDAO) DeleteAll() error
- func (d *EventHistoryDAO) FindAllBackward(userID int64, fromDate time.Time) ([]int64, error)
- func (d *EventHistoryDAO) FindAllForward(userID int64, fromDate time.Time) ([]int64, error)
- func (d *EventHistoryDAO) Insert(userID int64, entry *api.TimeLineEntryDTO) error
- func (d *EventHistoryDAO) InsertBatch(entry *api.TimeLineEntryDTO, userIDs ...int64) error
- type EventTimeLineDAO
- func (d *EventTimeLineDAO) Delete(item *api.TimeLineEntryDTO) error
- func (d *EventTimeLineDAO) DeleteAll() error
- func (d *EventTimeLineDAO) FindAllBackward(date time.Time) ([]*api.TimeLineEntryDTO, error)
- func (d *EventTimeLineDAO) FindAllBetween(fromDate time.Time, toDate time.Time) ([]*api.TimeLineEntryDTO, error)
- func (d *EventTimeLineDAO) FindAllForward(date time.Time) ([]*api.TimeLineEntryDTO, error)
- func (d *EventTimeLineDAO) Insert(item *api.TimeLineEntryDTO) error
- func (d *EventTimeLineDAO) Replace(oldItem *api.TimeLineEntryDTO, newItem *api.TimeLineEntryDTO) error
- type FriendDAO
- func (d *FriendDAO) AddMembers(user_id int64, group_id int32, friend_ids ...int64) error
- func (dao *FriendDAO) ContainsFriend(user_id int64, other_user_id int64) (bool, error)
- func (dao *FriendDAO) DeleteGroup(user_id int64, group_id int32) error
- func (d *FriendDAO) DeleteMembers(user_id int64, group_id int32, friend_ids ...int64) error
- func (dao *FriendDAO) InsertGroup(user_id int64, group *api.GroupDTO) error
- func (d *FriendDAO) LoadFriends(user_id int64, group_id int32) ([]*api.FriendDTO, error)
- func (d *FriendDAO) LoadGroups(user_id int64) ([]*api.GroupDTO, error)
- func (dao *FriendDAO) LoadGroupsWithMembers(user_id int64) ([]*api.GroupDTO, error)
- func (dao *FriendDAO) MakeFriends(user1 *api.FriendDTO, user2 *api.FriendDTO) error
- func (dao *FriendDAO) SetFriendPictureDigest(user_id int64, friend_id int64, digest []byte) error
- func (dao *FriendDAO) SetGroupName(user_id int64, group_id int32, name string) error
- type FriendRequestDAO
- func (d *FriendRequestDAO) Delete(friendRequest *api.FriendRequestDTO) error
- func (d *FriendRequestDAO) Exist(fromUser int64, toUser int64) (bool, error)
- func (d *FriendRequestDAO) Insert(friendRequest *api.FriendRequestDTO) error
- func (d *FriendRequestDAO) Load(fromUser int64, toUser int64) (*api.FriendRequestDTO, error)
- func (d *FriendRequestDAO) LoadAll(user_id int64) ([]*api.FriendRequestDTO, error)
- type GocqlSession
- type LogDAO
- type SettingsDAO
- type ThumbnailDAO
- type UserDAO
- func (dao *UserDAO) Delete(user *api.UserDTO) error
- func (d *UserDAO) DeleteAll() error
- func (d *UserDAO) Insert(user *api.UserDTO) error
- func (d *UserDAO) InsertFacebookCredentials(userId int64, fbId string, fbToken string) (ok bool, err error)
- func (d *UserDAO) Int_CheckUserConsistency(user *api.UserDTO) (bool, error)
- func (d *UserDAO) Int_LoadAllUserAccount() ([]*api.UserDTO, error)
- func (d *UserDAO) Int_LoadEmailCredential(email string) (*emailCredential, error)
- func (d *UserDAO) Int_LoadFacebookCredential(fbId string) (*fbCredential, error)
- func (d *UserDAO) Int_LoadUserAccount(userId int64) (*api.UserDTO, error)
- func (d *UserDAO) Load(userId int64) (*api.UserDTO, error)
- func (d *UserDAO) LoadByEmail(email string) (*api.UserDTO, error)
- func (d *UserDAO) LoadByFB(fbId string) (*api.UserDTO, error)
- func (d *UserDAO) LoadIIDToken(userId int64) (*api.IIDTokenDTO, error)
- func (d *UserDAO) LoadProfilePicture(user_id int64) (*api.PictureDTO, error)
- func (d *UserDAO) SaveProfilePicture(user_id int64, picture *api.PictureDTO) error
- func (d *UserDAO) SetAuthToken(user_id int64, auth_token string) error
- func (d *UserDAO) SetFacebook(userID int64, fbID string, fbToken string) error
- func (d *UserDAO) SetFacebookCredential(userID int64, fbID string, fbToken string) error
- func (d *UserDAO) SetIIDToken(userID int64, iidToken *api.IIDTokenDTO) error
- func (d *UserDAO) SetLastConnection(user_id int64, time int64) error
- func (d *UserDAO) SetPassword(email string, newPassword [32]byte, newSalt [32]byte) (bool, error)
Constants ¶
const ( MAX_NUM_GUESTS = 100 // Not used by now MAX_EVENTS_IN_RECENT_LIST = 100 // Not used by now )
const ( MAX_NUM_FRIENDS = 1000 AVG_GROUPS_PER_USER = 10 )
const (
GRACE_PERIOD_MS = 15 * 1000 // 15s
)
const (
MAX_EVENTS_IN_HISTORY_LIST = 15
)
Variables ¶
var ( ErrNoSession = errors.New("no session to Cassandra available") ErrGracePeriod = errors.New("grace period due to old and new conflict") ErrUnexpected = errors.New("unexpected error") ErrInconsistency = errors.New("db inconsistency detected") ErrIllegalArguments = errors.New("illegal arguments") )
var (
EMPTY_ARRAY_32B = [32]byte{}
)
Functions ¶
func NewAccessTokenDAO ¶
func NewAccessTokenDAO(session api.DbSession) api.AccessTokenDAO
func NewEventHistoryDAO ¶
func NewEventHistoryDAO(session api.DbSession) api.EventHistoryDAO
func NewFriendRequestDAO ¶
func NewFriendRequestDAO(session api.DbSession) api.FriendRequestDAO
func NewSettingsDAO ¶
func NewSettingsDAO(session api.DbSession) api.SettingsDAO
func NewThumbnailDAO ¶
func NewThumbnailDAO(session api.DbSession) api.ThumbnailDAO
func NewTimeLineDAO ¶
func NewTimeLineDAO(session api.DbSession) api.EventTimeLineDAO
Types ¶
type AccessTokenDAO ¶
type AccessTokenDAO struct {
// contains filtered or unexported fields
}
func (*AccessTokenDAO) Insert ¶
func (d *AccessTokenDAO) Insert(accessToken *api.AccessTokenDTO) error
func (*AccessTokenDAO) Load ¶
func (d *AccessTokenDAO) Load(userId int64) (*api.AccessTokenDTO, error)
func (*AccessTokenDAO) Remove ¶
func (d *AccessTokenDAO) Remove(userId int64) error
func (*AccessTokenDAO) SetLastUsed ¶
func (d *AccessTokenDAO) SetLastUsed(user_id int64, time int64) error
type EventDAO ¶
type EventDAO struct {
// contains filtered or unexported fields
}
func (*EventDAO) Insert ¶
Insert event into database with timestamp the one of the event. Participant will have the same timestamp.
func (*EventDAO) InsertParticipant ¶
func (d *EventDAO) InsertParticipant(p *api.ParticipantDTO) error
func (*EventDAO) LoadEventPicture ¶
func (de *EventDAO) LoadEventPicture(event_id int64) (*api.PictureDTO, error)
func (*EventDAO) LoadEvents ¶
Read one or more events and their participants. Event info and participants are in the same partition
func (*EventDAO) LoadParticipant ¶
func (*EventDAO) RangeEvents ¶
func (*EventDAO) Replace ¶
Replace modifies information of an existing event. This implementation only changes message, start_date, end_date, inbox_position and event state. Moreover, it doesn't modify information related to existing participants but only can add new ones where version isn't set. NOTE: This implementation takes into account the single use case where an event update contains new participants only.
func (*EventDAO) SetEventPicture ¶
func (dao *EventDAO) SetEventPicture(event_id int64, picture *api.PictureDTO) error
type EventHistoryDAO ¶
type EventHistoryDAO struct {
// contains filtered or unexported fields
}
func (*EventHistoryDAO) DeleteAll ¶
func (d *EventHistoryDAO) DeleteAll() error
func (*EventHistoryDAO) FindAllBackward ¶
func (*EventHistoryDAO) FindAllForward ¶
func (*EventHistoryDAO) Insert ¶
func (d *EventHistoryDAO) Insert(userID int64, entry *api.TimeLineEntryDTO) error
func (*EventHistoryDAO) InsertBatch ¶
func (d *EventHistoryDAO) InsertBatch(entry *api.TimeLineEntryDTO, userIDs ...int64) error
type EventTimeLineDAO ¶
type EventTimeLineDAO struct {
// contains filtered or unexported fields
}
Beginning of time line has the event with earliest end date
func (*EventTimeLineDAO) Delete ¶
func (d *EventTimeLineDAO) Delete(item *api.TimeLineEntryDTO) error
func (*EventTimeLineDAO) DeleteAll ¶
func (d *EventTimeLineDAO) DeleteAll() error
func (*EventTimeLineDAO) FindAllBackward ¶
func (d *EventTimeLineDAO) FindAllBackward(date time.Time) ([]*api.TimeLineEntryDTO, error)
func (*EventTimeLineDAO) FindAllBetween ¶
func (d *EventTimeLineDAO) FindAllBetween(fromDate time.Time, toDate time.Time) ([]*api.TimeLineEntryDTO, error)
func (*EventTimeLineDAO) FindAllForward ¶
func (d *EventTimeLineDAO) FindAllForward(date time.Time) ([]*api.TimeLineEntryDTO, error)
func (*EventTimeLineDAO) Insert ¶
func (d *EventTimeLineDAO) Insert(item *api.TimeLineEntryDTO) error
func (*EventTimeLineDAO) Replace ¶
func (d *EventTimeLineDAO) Replace(oldItem *api.TimeLineEntryDTO, newItem *api.TimeLineEntryDTO) error
type FriendDAO ¶
type FriendDAO struct {
// contains filtered or unexported fields
}
func (*FriendDAO) AddMembers ¶
Add one or more members into the same group
func (*FriendDAO) ContainsFriend ¶
func (*FriendDAO) DeleteGroup ¶
func (*FriendDAO) DeleteMembers ¶
Delete one or more members from the same group
func (*FriendDAO) InsertGroup ¶
Add a new group with members. If a group contains members, they must be all of the members in the group.
func (*FriendDAO) LoadFriends ¶
func (*FriendDAO) LoadGroups ¶
func (*FriendDAO) LoadGroupsWithMembers ¶
func (*FriendDAO) MakeFriends ¶
func (*FriendDAO) SetFriendPictureDigest ¶
type FriendRequestDAO ¶
type FriendRequestDAO struct {
// contains filtered or unexported fields
}
func (*FriendRequestDAO) Delete ¶
func (d *FriendRequestDAO) Delete(friendRequest *api.FriendRequestDTO) error
func (*FriendRequestDAO) Exist ¶
func (d *FriendRequestDAO) Exist(fromUser int64, toUser int64) (bool, error)
Check if exists a friend request from user_id to friend_id. In other words, if user_id has already sent (or not) a friend request to friend_id.
func (*FriendRequestDAO) Insert ¶
func (d *FriendRequestDAO) Insert(friendRequest *api.FriendRequestDTO) error
Insert a friend request into database. This request means that some user (friend_id) wants to be friend of user_id
func (*FriendRequestDAO) Load ¶
func (d *FriendRequestDAO) Load(fromUser int64, toUser int64) (*api.FriendRequestDTO, error)
func (*FriendRequestDAO) LoadAll ¶
func (d *FriendRequestDAO) LoadAll(user_id int64) ([]*api.FriendRequestDTO, error)
type GocqlSession ¶
func NewSession ¶
func NewSession(keyspace string, cqlVersion int, hosts ...string) *GocqlSession
func (*GocqlSession) Connect ¶
func (self *GocqlSession) Connect() error
func (*GocqlSession) IsValid ¶
func (self *GocqlSession) IsValid() bool
type LogDAO ¶
type LogDAO struct {
// contains filtered or unexported fields
}
func (*LogDAO) FindActiveSessions ¶
func (*LogDAO) LogActiveSession ¶
type SettingsDAO ¶
type SettingsDAO struct {
// contains filtered or unexported fields
}
func (*SettingsDAO) Find ¶
func (d *SettingsDAO) Find(key api.SettingOption) (string, error)
func (*SettingsDAO) Insert ¶
func (d *SettingsDAO) Insert(key api.SettingOption, value string) error
type ThumbnailDAO ¶
type ThumbnailDAO struct {
// contains filtered or unexported fields
}
func (*ThumbnailDAO) Insert ¶
Insert thumbnails into database. A batch implementation was used before, however it reaches Cassandra's batch_size limit of 50 Kb (despite being inserted to the same partition key). So a one-by-one insert implementation is preferred. If one of the inserts fails, this implementation keeps the first error but continues inserting the remainder ones. All errors are logged.
func (*ThumbnailDAO) Remove ¶
func (dao *ThumbnailDAO) Remove(id int64) error
type UserDAO ¶
type UserDAO struct {
// contains filtered or unexported fields
}
func (*UserDAO) Delete ¶
User information is spread in three tables: user_account, user_email_credentials and user_facebook_credentials. So, in order to delete a user, it's needed an user_id, e-mail and, likely, a Facebook ID. For the sake of safety, a read is perform before delete in order to perform security checks between data provided as argument and data stored in database. If all of the security checks passed, then user is removed.
func (*UserDAO) Insert ¶
Insert a new user into Cassandra involving tables user_account, user_email_credentials and user_facebook_credentials. It takes account race conditions like two users trying to create the same account simultaneously. If email is already taken this operation fails. In the same way, if FB account is already linked to a valid user account (row exists in user_account and user_email_credential), then this operation fails. With this implementation, orphan fb rows are removed after a grace period time in order to enable retry logic in the client when, by some reason, registration failed at first attempt. This function does not remove user account, it only updates orphaned user_facebook_credentials rows that doesn't point to a valid user account. In order to work properly, a row in user_email_credentials must be inserted before GRACE_PERIOD_MS. Otherwise, another account could reclaim that FB for itself with another Insert call.
func (*UserDAO) InsertFacebookCredentials ¶
func (d *UserDAO) InsertFacebookCredentials(userId int64, fbId string, fbToken string) (ok bool, err error)
Try to insert Facebook credentials. If it fails because of a collision, retrieve the row causing that collision, compare created_date with grace_period and check if that row belongs to a valid account. If grace_period seconds have elapsed since created_date and account isn't valid, then remove row causing conflict and retry. Otherwise, if account is valid, returns ErrFacebookAlreadyExists. If grace_period seconds haven't elapsed yet since created_date then return ErrGracePeriod .
func (*UserDAO) Int_CheckUserConsistency ¶
func (*UserDAO) Int_LoadAllUserAccount ¶
TODO: Include Password and Salt in user_account table TODO: Make up some type of high level iterator in order to control scanning steps in model layer.
func (*UserDAO) Int_LoadEmailCredential ¶
func (*UserDAO) Int_LoadFacebookCredential ¶
func (*UserDAO) Int_LoadUserAccount ¶
func (*UserDAO) LoadIIDToken ¶
func (d *UserDAO) LoadIIDToken(userId int64) (*api.IIDTokenDTO, error)
func (*UserDAO) LoadProfilePicture ¶
func (d *UserDAO) LoadProfilePicture(user_id int64) (*api.PictureDTO, error)
func (*UserDAO) SaveProfilePicture ¶
func (d *UserDAO) SaveProfilePicture(user_id int64, picture *api.PictureDTO) error
func (*UserDAO) SetAuthToken ¶
func (*UserDAO) SetFacebook ¶
SetFacebook sets facebook id and access token for the account user_id regardless fbId exists also as facebook credentials.
func (*UserDAO) SetFacebookCredential ¶
UpdateFacebookCredential sets facebook id and access token for the account user_id and also set facebook as credential
func (*UserDAO) SetIIDToken ¶
func (d *UserDAO) SetIIDToken(userID int64, iidToken *api.IIDTokenDTO) error