diff --git a/cmd/collect/main.go b/cmd/collect/main.go index 5699ac6..49ccbde 100644 --- a/cmd/collect/main.go +++ b/cmd/collect/main.go @@ -169,74 +169,79 @@ func main() { // *osReleasePrettyName = "Linux" // } - rec := records.Record{ - // posix - Cols: *cols, - Lines: *lines, - // core - BaseRecord: records.BaseRecord{ - RecallHistno: *recallHistno, - - CmdLine: *cmdLine, - ExitCode: *exitCode, - Shell: *shell, - Uname: *uname, - SessionID: *sessionID, - - // posix - Home: *home, - Lang: *lang, - LcAll: *lcAll, - Login: *login, - // Path: *path, - Pwd: *pwd, - ShellEnv: *shellEnv, - Term: *term, - - // non-posix - RealPwd: realPwd, - Pid: *pid, - SessionPID: *sessionPid, - Host: *host, - Hosttype: *hosttype, - Ostype: *ostype, - Machtype: *machtype, - Shlvl: *shlvl, - - // before after - TimezoneBefore: *timezoneBefore, - - RealtimeBefore: realtimeBefore, - RealtimeBeforeLocal: realtimeBeforeLocal, - - RealtimeSinceSessionStart: realtimeSinceSessionStart, - RealtimeSinceBoot: realtimeSinceBoot, - - GitDir: gitDir, - GitRealDir: gitRealDir, - GitOriginRemote: *gitRemote, - MachineID: collect.ReadFileContent(machineIDPath), - - OsReleaseID: *osReleaseID, - OsReleaseVersionID: *osReleaseVersionID, - OsReleaseIDLike: *osReleaseIDLike, - OsReleaseName: *osReleaseName, - OsReleasePrettyName: *osReleasePrettyName, - - PartOne: true, - - ReshUUID: collect.ReadFileContent(reshUUIDPath), - ReshVersion: Version, - ReshRevision: Revision, - - RecallActionsRaw: *recallActions, - RecallPrefix: *recallPrefix, - RecallStrategy: *recallStrategy, - }, - } if *recall { + rec := records.SlimRecord{ + SessionID: *sessionID, + RecallHistno: *recallHistno, + RecallPrefix: *recallPrefix, + } fmt.Print(collect.SendRecallRequest(rec, strconv.Itoa(config.Port))) } else { + rec := records.Record{ + // posix + Cols: *cols, + Lines: *lines, + // core + BaseRecord: records.BaseRecord{ + RecallHistno: *recallHistno, + + CmdLine: *cmdLine, + ExitCode: *exitCode, + Shell: *shell, + Uname: *uname, + SessionID: *sessionID, + + // posix + Home: *home, + Lang: *lang, + LcAll: *lcAll, + Login: *login, + // Path: *path, + Pwd: *pwd, + ShellEnv: *shellEnv, + Term: *term, + + // non-posix + RealPwd: realPwd, + Pid: *pid, + SessionPID: *sessionPid, + Host: *host, + Hosttype: *hosttype, + Ostype: *ostype, + Machtype: *machtype, + Shlvl: *shlvl, + + // before after + TimezoneBefore: *timezoneBefore, + + RealtimeBefore: realtimeBefore, + RealtimeBeforeLocal: realtimeBeforeLocal, + + RealtimeSinceSessionStart: realtimeSinceSessionStart, + RealtimeSinceBoot: realtimeSinceBoot, + + GitDir: gitDir, + GitRealDir: gitRealDir, + GitOriginRemote: *gitRemote, + MachineID: collect.ReadFileContent(machineIDPath), + + OsReleaseID: *osReleaseID, + OsReleaseVersionID: *osReleaseVersionID, + OsReleaseIDLike: *osReleaseIDLike, + OsReleaseName: *osReleaseName, + OsReleasePrettyName: *osReleasePrettyName, + + PartOne: true, + + ReshUUID: collect.ReadFileContent(reshUUIDPath), + ReshVersion: Version, + ReshRevision: Revision, + + RecallActionsRaw: *recallActions, + RecallPrefix: *recallPrefix, + RecallStrategy: *recallStrategy, + }, + } collect.SendRecord(rec, strconv.Itoa(config.Port), "/record") } } diff --git a/cmd/daemon/recall.go b/cmd/daemon/recall.go index 0f0ad83..d5f831b 100644 --- a/cmd/daemon/recall.go +++ b/cmd/daemon/recall.go @@ -24,7 +24,7 @@ func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - rec := records.Record{} + rec := records.SlimRecord{} log.Println("/recall unmarshaling record ...") err = json.Unmarshal(jsn, &rec) if err != nil { diff --git a/pkg/collect/collect.go b/pkg/collect/collect.go index 7f26b4e..56ee374 100644 --- a/pkg/collect/collect.go +++ b/pkg/collect/collect.go @@ -19,7 +19,7 @@ type SingleResponse struct { } // SendRecallRequest to daemon -func SendRecallRequest(r records.Record, port string) string { +func SendRecallRequest(r records.SlimRecord, port string) string { recJSON, err := json.Marshal(r) if err != nil { log.Fatal("send err 1", err) diff --git a/pkg/records/records.go b/pkg/records/records.go index 3b4170a..319f0a0 100644 --- a/pkg/records/records.go +++ b/pkg/records/records.go @@ -129,6 +129,21 @@ type FallbackRecord struct { Lines int `json:"lines"` // notice the int type } +// SlimRecord used for recalling because unmarshalling record w/ 50+ fields is too slow +type SlimRecord struct { + SessionID string `json:"sessionId"` + RecallHistno int `json:"recallHistno,omitempty"` + RecallPrefix string `json:"recallPrefix,omitempty"` + + // extra recall - we might use these in the future + // Pwd string `json:"pwd"` + // RealPwd string `json:"realPwd"` + // GitDir string `json:"gitDir"` + // GitRealDir string `json:"gitRealDir"` + // GitOriginRemote string `json:"gitOriginRemote"` + +} + // Convert from FallbackRecord to Record func Convert(r *FallbackRecord) Record { return Record{