mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
fix history query time
This commit is contained in:
@@ -0,0 +1 @@
|
||||
ALTER TABLE history DROP COLUMN linenum;
|
||||
@@ -0,0 +1,6 @@
|
||||
ALTER TABLE history ADD COLUMN linenum int NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE history
|
||||
SET linenum = COALESCE((SELECT line.linenum FROM line WHERE line.lineid = history.lineid), 0)
|
||||
;
|
||||
|
||||
@@ -95,6 +95,7 @@ type SetVarScope struct {
|
||||
|
||||
type historyContextType struct {
|
||||
LineId string
|
||||
LineNum int64
|
||||
CmdId string
|
||||
RemotePtr *sstore.RemotePtrType
|
||||
}
|
||||
@@ -378,6 +379,7 @@ func addToHistory(ctx context.Context, pk *scpacket.FeCommandPacketType, history
|
||||
SessionId: ids.SessionId,
|
||||
ScreenId: ids.ScreenId,
|
||||
LineId: historyContext.LineId,
|
||||
LineNum: historyContext.LineNum,
|
||||
HadError: hadError,
|
||||
CmdId: historyContext.CmdId,
|
||||
CmdStr: cmdStr,
|
||||
@@ -1240,6 +1242,7 @@ func updateHistoryContext(ctx context.Context, line *sstore.LineType, cmd *sstor
|
||||
hctx := ctxVal.(*historyContextType)
|
||||
if line != nil {
|
||||
hctx.LineId = line.LineId
|
||||
hctx.LineNum = line.LineNum
|
||||
}
|
||||
if cmd != nil {
|
||||
hctx.CmdId = cmd.CmdId
|
||||
|
||||
+4
-4
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/scripthaus-dev/sh2-server/pkg/scbase"
|
||||
)
|
||||
|
||||
const HistoryCols = "h.historyid, h.ts, h.userid, h.sessionid, h.screenid, h.lineid, h.cmdid, h.haderror, h.cmdstr, h.remoteownerid, h.remoteid, h.remotename, h.ismetacmd, h.incognito"
|
||||
const HistoryCols = "h.historyid, h.ts, h.userid, h.sessionid, h.screenid, h.lineid, h.cmdid, h.haderror, h.cmdstr, h.remoteownerid, h.remoteid, h.remotename, h.ismetacmd, h.incognito, h.linenum"
|
||||
const DefaultMaxHistoryItems = 1000
|
||||
|
||||
type SingleConnDBGetter struct {
|
||||
@@ -187,8 +187,8 @@ func InsertHistoryItem(ctx context.Context, hitem *HistoryItemType) error {
|
||||
}
|
||||
txErr := WithTx(ctx, func(tx *TxWrap) error {
|
||||
query := `INSERT INTO history
|
||||
( historyid, ts, userid, sessionid, screenid, lineid, cmdid, haderror, cmdstr, remoteownerid, remoteid, remotename, ismetacmd, incognito) VALUES
|
||||
(:historyid,:ts,:userid,:sessionid,:screenid,:lineid,:cmdid,:haderror,:cmdstr,:remoteownerid,:remoteid,:remotename,:ismetacmd,:incognito)`
|
||||
( historyid, ts, userid, sessionid, screenid, lineid, cmdid, haderror, cmdstr, remoteownerid, remoteid, remotename, ismetacmd, incognito, linenum) VALUES
|
||||
(:historyid,:ts,:userid,:sessionid,:screenid,:lineid,:cmdid,:haderror,:cmdstr,:remoteownerid,:remoteid,:remotename,:ismetacmd,:incognito,:linenum)`
|
||||
tx.NamedExec(query, hitem.ToMap())
|
||||
return nil
|
||||
})
|
||||
@@ -315,7 +315,7 @@ func runHistoryQuery(tx *TxWrap, opts HistoryQueryOpts, realOffset int, itemLimi
|
||||
if opts.NoMeta {
|
||||
whereClause += " AND NOT h.ismetacmd"
|
||||
}
|
||||
query := fmt.Sprintf("SELECT %s, ('%s' || CAST((row_number() OVER win) as text)) historynum, l.linenum FROM history h LEFT OUTER JOIN line l ON (h.lineid = l.lineid) %s WINDOW win AS (ORDER BY h.ts, h.historyid) ORDER BY h.ts DESC, h.historyid DESC LIMIT %d OFFSET %d", HistoryCols, hNumStr, whereClause, itemLimit, realOffset)
|
||||
query := fmt.Sprintf("SELECT %s, ('%s' || CAST((row_number() OVER win) as text)) historynum FROM history h %s WINDOW win AS (ORDER BY h.ts, h.historyid) ORDER BY h.ts DESC, h.historyid DESC LIMIT %d OFFSET %d", HistoryCols, hNumStr, whereClause, itemLimit, realOffset)
|
||||
marr := tx.SelectMaps(query, queryArgs...)
|
||||
rtn := make([]*HistoryItemType, len(marr))
|
||||
for idx, m := range marr {
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
)
|
||||
|
||||
const MaxMigration = 11
|
||||
const MaxMigration = 12
|
||||
const MigratePrimaryScreenVersion = 9
|
||||
|
||||
func MakeMigrate() (*migrate.Migrate, error) {
|
||||
|
||||
Reference in New Issue
Block a user