Ejemplo n.º 1
0
func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	UserKey := GenerateUserKey(args.UserID)

	_, err := ts.lib.Get(UserKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.Tribbles = nil
		return nil
	}

	SubsKey := GenerateSubsKey(args.UserID)
	SubsList, err := ts.lib.GetList(SubsKey)
	if err != nil {
		//reply.Status = tribrpc.NoSuchUser
		reply.Status = tribrpc.OK
		reply.Tribbles = nil
		return nil
	}

	for i := 0; i < len(SubsList); i++ {
		var Subargs tribrpc.GetTribblesArgs
		var Subreply tribrpc.GetTribblesReply

		Subargs.UserID = SubsList[i]
		err = ts.GetTribbles(&Subargs, &Subreply)
		if err != nil {
			return err
		}

		reply.Tribbles = append(reply.Tribbles, Subreply.Tribbles...)
	}

	var tempTrib Tribs
	tempTrib = reply.Tribbles
	sort.Sort(tempTrib)
	if len(tempTrib) > 100 {
		reply.Status = tribrpc.OK
		reply.Tribbles = tempTrib[:100]
	} else {
		reply.Status = tribrpc.OK
		reply.Tribbles = tempTrib
	}

	return nil
}
Ejemplo n.º 2
0
func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	LOGE.Printf("GetTribblesBySubscription:: args=%s\n", string(marshal(*args)))
	userIDKey := GetUserKey(args.UserID)
	_, err := ts.lib.Get(userIDKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.Tribbles = nil
		return nil
	}

	userTribleListKey := GetsSubsKey(args.UserID)
	subsList, err := ts.lib.GetList(userTribleListKey)
	if err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = nil
		return nil
	}

	for i := 0; i < len(subsList); i++ {
		var subArgs tribrpc.GetTribblesArgs
		var subReply tribrpc.GetTribblesReply

		subArgs.UserID = subsList[i]

		err = ts.GetTribbles(&subArgs, &subReply)
		if err != nil {
			return err
		}
		reply.Tribbles = append(reply.Tribbles, subReply.Tribbles...)
	}

	var tempTribbles Tribs
	tempTribbles = reply.Tribbles
	sort.Sort(tempTribbles)
	if len(tempTribbles) > 100 {
		reply.Status = tribrpc.OK
		reply.Tribbles = tempTribbles[:100]
	} else {
		reply.Status = tribrpc.OK
		reply.Tribbles = tempTribbles
	}
	LOGE.Printf("GetTribblesBySubscription:: reply=%s\n", string(marshal(reply)))
	return nil
}