Skip to content

Commit

Permalink
Add user count to pds list endpoint (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvolp12 authored Nov 10, 2023
2 parents d47a672 + d51abd2 commit 668f3da
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bgs/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ type enrichedPDS struct {
EventsSeenSinceStartup uint64 `json:"EventsSeenSinceStartup"`
IngestRate rateLimit `json:"IngestRate"`
CrawlRate rateLimit `json:"CrawlRate"`
UserCount int64 `json:"UserCount"`
}

type UserCount struct {
PDSID uint `gorm:"column:pds"`
UserCount int64 `gorm:"column:user_count"`
}

func (bgs *BGS) handleListPDSs(e echo.Context) error {
Expand All @@ -118,6 +124,20 @@ func (bgs *BGS) handleListPDSs(e echo.Context) error {

activePDSHosts := bgs.slurper.GetActiveList()

var userCounts []UserCount
if err := bgs.db.Model(&User{}).
Select("pds, count(*) as user_count").
Group("pds").
Find(&userCounts).Error; err != nil {
return err
}

// Create a map for fast lookup
userCountMap := make(map[uint]int64)
for _, count := range userCounts {
userCountMap[count.PDSID] = count.UserCount
}

for i, p := range pds {
enrichedPDSs[i].PDS = p
enrichedPDSs[i].HasActiveConnection = false
Expand All @@ -133,6 +153,7 @@ func (bgs *BGS) handleListPDSs(e echo.Context) error {
continue
}
enrichedPDSs[i].EventsSeenSinceStartup = uint64(m.Counter.GetValue())
enrichedPDSs[i].UserCount = userCountMap[p.ID]

// Get the ingest rate limit for this PDS
ingestRate := rateLimit{
Expand Down
34 changes: 34 additions & 0 deletions ts/bgs-dash/src/components/Dash/Dash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,37 @@ const Dash: FC<{}> = () => {
</span>
</a>
</th>
<th
scope="col"
className="px-3 py-3.5 text-right text-sm font-semibold text-gray-900 pr-6 whitespace-nowrap"
>
<a
href="#"
className="group inline-flex"
onClick={() => {
setSortField("UserCount");
setSortOrder(sortOrder === "asc" ? "desc" : "asc");
}}
>
Users
<span
className={`ml-2 flex-none rounded text-gray-400 ${
sortField === "UserCount"
? "group-hover:bg-gray-200"
: "invisible group-hover:visible group-focus:visible"
}`}
>
{sortField === "UserCount" && sortOrder === "asc" ? (
<ChevronUpIcon className="h-5 w-5" aria-hidden="true" />
) : (
<ChevronDownIcon
className="h-5 w-5"
aria-hidden="true"
/>
)}
</span>
</a>
</th>
<th
scope="col"
className="px-3 py-3.5 text-right text-sm font-semibold text-gray-900 pr-6 whitespace-nowrap"
Expand Down Expand Up @@ -810,6 +841,9 @@ const Dash: FC<{}> = () => {
</div>
)}
</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-400 text-center w-8 pr-6">
{pds.UserCount?.toLocaleString()}
</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-400 text-center w-8 pr-6">
{pds.EventsSeenSinceStartup?.toLocaleString()}
</td>
Expand Down
1 change: 1 addition & 0 deletions ts/bgs-dash/src/models/pds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface PDS {
EventsSeenSinceStartup?: number;
IngestRate: RateLimit;
CrawlRate: RateLimit;
UserCount: number;
}

type PDSKey = keyof PDS;
Expand Down

0 comments on commit 668f3da

Please sign in to comment.