Skip to content

Commit

Permalink
Merge pull request #1056 from gobitfly/BEDS-902/Use_ts_instead_of_epoch
Browse files Browse the repository at this point in the history
Used ts column instead of epoch
  • Loading branch information
peterbitfly authored Oct 31, 2024
2 parents edb982b + 75459b0 commit e66a3ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
35 changes: 18 additions & 17 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func (d *DataAccessService) GetMachineNotifications(ctx context.Context, userId
// -------------------------------------
// Get the machine notification history
notificationHistory := []struct {
Epoch uint64 `db:"epoch"`
Ts time.Time `db:"ts"`
MachineId uint64 `db:"machine_id"`
MachineName string `db:"machine_name"`
EventType types.EventName `db:"event_type"`
Expand All @@ -720,7 +720,7 @@ func (d *DataAccessService) GetMachineNotifications(ctx context.Context, userId

ds := goqu.Dialect("postgres").
Select(
goqu.L("epoch"),
goqu.L("ts"),
goqu.L("machine_id"),
goqu.L("machine_name"),
goqu.L("event_type"),
Expand All @@ -735,8 +735,9 @@ func (d *DataAccessService) GetMachineNotifications(ctx context.Context, userId
}

// Sorting and limiting if cursor is present
// Rows can be uniquely identified by (ts, machine_id, event_type)
defaultColumns := []t.SortColumn{
{Column: enums.NotificationsMachinesColumns.Timestamp.ToExpr(), Desc: true, Offset: currentCursor.Epoch},
{Column: enums.NotificationsMachinesColumns.Timestamp.ToExpr(), Desc: true, Offset: currentCursor.Ts},
{Column: enums.NotificationsMachinesColumns.MachineId.ToExpr(), Desc: false, Offset: currentCursor.MachineId},
{Column: enums.NotificationsMachinesColumns.EventType.ToExpr(), Desc: false, Offset: currentCursor.EventType},
}
Expand Down Expand Up @@ -771,7 +772,7 @@ func (d *DataAccessService) GetMachineNotifications(ctx context.Context, userId
resultEntry := t.NotificationMachinesTableRow{
MachineName: notification.MachineName,
Threshold: notification.EventThreshold,
Timestamp: utils.EpochToTime(notification.Epoch).Unix(),
Timestamp: notification.Ts.Unix(),
}
switch notification.EventType {
case types.MonitoringMachineOfflineEventName:
Expand Down Expand Up @@ -833,15 +834,15 @@ func (d *DataAccessService) GetClientNotifications(ctx context.Context, userId u
// -------------------------------------
// Get the client notification history
notificationHistory := []struct {
Epoch uint64 `db:"epoch"`
Client string `db:"client"`
Version string `db:"client_version"`
Url string `db:"client_url"`
Ts time.Time `db:"ts"`
Client string `db:"client"`
Version string `db:"client_version"`
Url string `db:"client_url"`
}{}

ds := goqu.Dialect("postgres").
Select(
goqu.L("epoch"),
goqu.L("ts"),
goqu.L("client"),
goqu.L("client_version"),
goqu.L("client_url")).
Expand All @@ -855,9 +856,9 @@ func (d *DataAccessService) GetClientNotifications(ctx context.Context, userId u
}

// Sorting and limiting if cursor is present
// Rows can be uniquely identified by (epoch, client)
// Rows can be uniquely identified by (ts, client)
defaultColumns := []t.SortColumn{
{Column: enums.NotificationsClientsColumns.Timestamp.ToExpr(), Desc: true, Offset: currentCursor.Epoch},
{Column: enums.NotificationsClientsColumns.Timestamp.ToExpr(), Desc: true, Offset: currentCursor.Ts},
{Column: enums.NotificationsClientsColumns.ClientName.ToExpr(), Desc: false, Offset: currentCursor.Client},
}
order, directions := applySortAndPagination(defaultColumns, t.SortColumn{Column: colSort.Column.ToExpr(), Desc: colSort.Desc}, currentCursor.GenericCursor)
Expand All @@ -884,7 +885,7 @@ func (d *DataAccessService) GetClientNotifications(ctx context.Context, userId u
ClientName: notification.Client,
Version: notification.Version,
Url: notification.Url,
Timestamp: utils.EpochToTime(notification.Epoch).Unix(),
Timestamp: notification.Ts.Unix(),
}
result = append(result, resultEntry)
}
Expand Down Expand Up @@ -935,15 +936,15 @@ func (d *DataAccessService) GetNetworkNotifications(ctx context.Context, userId
// -------------------------------------
// Get the network notification history
notificationHistory := []struct {
Epoch uint64 `db:"epoch"`
Ts time.Time `db:"ts"`
Network uint64 `db:"network"`
EventType types.EventName `db:"event_type"`
EventThreshold float64 `db:"event_threshold"`
}{}

ds := goqu.Dialect("postgres").
Select(
goqu.L("epoch"),
goqu.L("ts"),
goqu.L("network"),
goqu.L("event_type"),
goqu.L("event_threshold")).
Expand All @@ -952,9 +953,9 @@ func (d *DataAccessService) GetNetworkNotifications(ctx context.Context, userId
Limit(uint(limit + 1))

// Sorting and limiting if cursor is present
// Rows can be uniquely identified by (epoch, network, event_type)
// Rows can be uniquely identified by (ts, network, event_type)
defaultColumns := []t.SortColumn{
{Column: enums.NotificationNetworksColumns.Timestamp.ToExpr(), Desc: true, Offset: currentCursor.Epoch},
{Column: enums.NotificationNetworksColumns.Timestamp.ToExpr(), Desc: true, Offset: currentCursor.Ts},
{Column: enums.NotificationNetworksColumns.Network.ToExpr(), Desc: false, Offset: currentCursor.Network},
{Column: enums.NotificationNetworksColumns.EventType.ToExpr(), Desc: false, Offset: currentCursor.EventType},
}
Expand All @@ -980,7 +981,7 @@ func (d *DataAccessService) GetNetworkNotifications(ctx context.Context, userId
for _, notification := range notificationHistory {
resultEntry := t.NotificationNetworksTableRow{
ChainId: notification.Network,
Timestamp: utils.EpochToTime(notification.Epoch).Unix(),
Timestamp: notification.Ts.Unix(),
}
switch notification.EventType {
case types.NetworkGasAboveThresholdEventName:
Expand Down
6 changes: 3 additions & 3 deletions backend/pkg/api/types/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ type NotificationMachinesCursor struct {
MachineName string
EventType string
EventThreshold float64
Epoch uint64
Ts time.Time
}

type NotificationClientsCursor struct {
GenericCursor

Client string
Epoch uint64
Ts time.Time
}

type NotificationRocketPoolsCursor struct {
Expand All @@ -151,7 +151,7 @@ type NotificationNetworksCursor struct {
GenericCursor

Network uint64
Epoch uint64
Ts time.Time
EventType string
}

Expand Down

0 comments on commit e66a3ce

Please sign in to comment.