@@ -40,6 +40,7 @@ type cpuSample struct {
4040// widgetPidOrder stores the ordered pid list from the last non-LastPidOrder request for a widget.
4141type widgetPidOrder struct {
4242 pids []int32
43+ totalCount int
4344 lastRequest time.Time
4445}
4546
@@ -116,7 +117,7 @@ func (s *procCacheState) touchWidgetPidOrder(widgetId string) {
116117 }
117118}
118119
119- func (s * procCacheState ) storeWidgetPidOrder (widgetId string , pids []int32 ) {
120+ func (s * procCacheState ) storeWidgetPidOrder (widgetId string , pids []int32 , totalCount int ) {
120121 if widgetId == "" {
121122 return
122123 }
@@ -127,28 +128,29 @@ func (s *procCacheState) storeWidgetPidOrder(widgetId string, pids []int32) {
127128 }
128129 s .widgetPidOrders [widgetId ] = & widgetPidOrder {
129130 pids : pids ,
131+ totalCount : totalCount ,
130132 lastRequest : time .Now (),
131133 }
132134}
133135
134- func (s * procCacheState ) getWidgetPidOrder (widgetId string ) []int32 {
136+ func (s * procCacheState ) getWidgetPidOrder (widgetId string ) ( []int32 , int ) {
135137 if widgetId == "" {
136- return nil
138+ return nil , 0
137139 }
138140 s .lock .Lock ()
139141 defer s .lock .Unlock ()
140142 if s .widgetPidOrders == nil {
141- return nil
143+ return nil , 0
142144 }
143145 entry , ok := s .widgetPidOrders [widgetId ]
144146 if ! ok {
145- return nil
147+ return nil , 0
146148 }
147149 if time .Since (entry .lastRequest ) >= ProcCacheIdleTimeout {
148150 delete (s .widgetPidOrders , widgetId )
149- return nil
151+ return nil , 0
150152 }
151- return entry .pids
153+ return entry .pids , entry . totalCount
152154}
153155
154156func (s * procCacheState ) runLoop (firstReadyCh chan struct {}) {
@@ -505,7 +507,12 @@ func (impl *ServerImpl) RemoteProcessListCommand(ctx context.Context, data wshrp
505507 var pidOrder []int32
506508 var filteredCount int
507509 if data .LastPidOrder {
508- pidOrder = procCache .getWidgetPidOrder (data .WidgetId )
510+ var cachedTotal int
511+ pidOrder , cachedTotal = procCache .getWidgetPidOrder (data .WidgetId )
512+ if pidOrder != nil {
513+ filteredCount = len (pidOrder )
514+ totalCount = cachedTotal
515+ }
509516 }
510517 if pidOrder == nil {
511518 sortBy := data .SortBy
@@ -524,7 +531,7 @@ func (impl *ServerImpl) RemoteProcessListCommand(ctx context.Context, data wshrp
524531 pidOrder [i ] = p .Pid
525532 }
526533 if data .WidgetId != "" {
527- procCache .storeWidgetPidOrder (data .WidgetId , pidOrder )
534+ procCache .storeWidgetPidOrder (data .WidgetId , pidOrder , totalCount )
528535 }
529536 }
530537
0 commit comments