Commit 2b2c3b48 authored by vicotor's avatar vicotor

fix bug

parent db94164e
......@@ -58,48 +58,91 @@ func manual(name string, bee string, sync_all bool) {
}
taskUser := core.UserObjectToUserTask(users)
slog.Info("GetFollowerList", "task id", todoTask.TaskId, "cursor", cursor, "len(users)", len(users), "newCursor", newCursor)
if (cursor != "" && newCursor == "") || (cursor != "" && newCursor == "0") {
slog.Info("Get all followers finished")
l := page.GetIdx().List
ok, l := page.GetIdx().Idx(taskUser)
if ok {
res := make([]core.UserTask, 0, l.Len())
for e := l.Front(); e != nil; e = e.Next() {
if user, ok := e.Value.(core.UserTask); ok {
res = append(res, user)
}
}
// save it to json file.
d, _ := json.MarshalIndent(res, "", " ")
filename := fmt.Sprintf("follower-%s.json", todoTask.TaskId)
err = os.WriteFile(filename, d, 0644)
if err != nil {
slog.Error("write followers", "err", err.Error())
} else {
slog.Info("write followers", "task id", todoTask.TaskId, "len(users)", len(res))
}
if err := core.InsertTaskRes(res, todoTask.TaskType, todoTask.TaskId); err != nil {
slog.Error("InsertTaskRes", "task id", todoTask.TaskId,
"t.TaskType", todoTask.TaskType, "len(users)", len(users), "err", err.Error())
} else {
slog.Info("InsertTaskRes", "task id", todoTask.TaskId, "len(users)", len(res))
}
return
} else {
ok, l := page.GetIdx().Idx(taskUser)
if ok {
if newCursor == "" || newCursor == "0" {
// all followers are found.
slog.Info("Get all followers finished")
l := page.GetIdx().List
res := make([]core.UserTask, 0, l.Len())
for e := l.Front(); e != nil; e = e.Next() {
if user, ok := e.Value.(core.UserTask); ok {
res = append(res, user)
}
}
// save it to json file.
d, _ := json.MarshalIndent(res, "", " ")
filename := fmt.Sprintf("follower-%s.json", todoTask.TaskId)
err = os.WriteFile(filename, d, 0644)
if err != nil {
slog.Error("write followers", "err", err.Error())
} else {
slog.Info("write followers", "task id", todoTask.TaskId, "len(users)", len(res))
}
if err := core.InsertTaskRes(res, todoTask.TaskType, todoTask.TaskId); err != nil {
slog.Error("InsertTaskRes", "task id", todoTask.TaskId,
"t.TaskType", todoTask.TaskType, "len(users)", len(users), "err", err.Error())
} else {
slog.Info("InsertTaskRes", "task id", todoTask.TaskId, "len(users)", len(res))
}
return
}
}
//if (cursor != "" && newCursor == "") || (cursor != "" && newCursor == "0") {
// slog.Info("Get all followers finished")
// l := page.GetIdx().List
// res := make([]core.UserTask, 0, l.Len())
// for e := l.Front(); e != nil; e = e.Next() {
// if user, ok := e.Value.(core.UserTask); ok {
// res = append(res, user)
// }
// }
// // save it to json file.
// d, _ := json.MarshalIndent(res, "", " ")
// filename := fmt.Sprintf("follower-%s.json", todoTask.TaskId)
// err = os.WriteFile(filename, d, 0644)
// if err != nil {
// slog.Error("write followers", "err", err.Error())
// } else {
// slog.Info("write followers", "task id", todoTask.TaskId, "len(users)", len(res))
// }
//
// if err := core.InsertTaskRes(res, todoTask.TaskType, todoTask.TaskId); err != nil {
// slog.Error("InsertTaskRes", "task id", todoTask.TaskId,
// "t.TaskType", todoTask.TaskType, "len(users)", len(users), "err", err.Error())
// }
// return
//} else {
// ok, l := page.GetIdx().Idx(taskUser)
// if ok {
// res := make([]core.UserTask, 0, l.Len())
// for e := l.Front(); e != nil; e = e.Next() {
// if user, ok := e.Value.(core.UserTask); ok {
// res = append(res, user)
// }
// }
// if err := core.InsertTaskRes(res, todoTask.TaskType, todoTask.TaskId); err != nil {
// slog.Error("InsertTaskRes", "task id", todoTask.TaskId,
// "t.TaskType", todoTask.TaskType, "len(users)", len(users), "err", err.Error())
// } else {
// slog.Info("InsertTaskRes", "task id", todoTask.TaskId, "len(users)", len(res))
// }
// return
// }
//}
if newCursor == "" || newCursor == "0" {
break
......
......@@ -35,6 +35,9 @@ func NewIdx(i []UserTask) *Idx {
}
func (s *Idx) Idx(page []UserTask) (bool, *list.List) {
if len(page) == 0 {
return false, nil
}
if s.idx != nil && len(s.idx) == 0 {
......@@ -61,7 +64,7 @@ func (s *Idx) Idx(page []UserTask) (bool, *list.List) {
}
}
if !match {
newItems.PushFront(v)
newItems.PushBack(v)
} else {
// stop, all new items has added to newItems.
break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment