Skip to content

Commit

Permalink
rename the RentableBy filter to RentableOrRentedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
Omarabdul3ziz committed Sep 18, 2024
1 parent d19b098 commit feca39e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
6 changes: 3 additions & 3 deletions grid-proxy/internal/explorer/db/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@ func (d *PostgresDatabase) GetNodes(ctx context.Context, filter types.NodeFilter
if filter.RentedBy != nil {
q = q.Where(`COALESCE(resources_cache.renter, 0) = ?`, *filter.RentedBy)
}
if filter.RentableBy != nil {
if filter.RentableOrRentedBy != nil {
q = q.Where(`((farm.dedicated_farm = true OR resources_cache.node_contracts_count = 0)
AND resources_cache.renter is null)
OR COALESCE(resources_cache.renter, 0) = ?
`, *filter.RentableBy)
`, *filter.RentableOrRentedBy)
}
if filter.Rented != nil {
q = q.Where(`? = (resources_cache.renter is not null)`, *filter.Rented)
Expand All @@ -730,7 +730,7 @@ func (d *PostgresDatabase) GetNodes(ctx context.Context, filter types.NodeFilter
q = q.Order("random()")
} else {
// prioritize the rented (by the twin) nodes
if filter.AvailableFor != nil || filter.RentableBy != nil {
if filter.AvailableFor != nil || filter.RentableOrRentedBy != nil {
q = q.Order("(case when resources_cache.renter is not null then 1 else 2 end)")
}

Expand Down
88 changes: 44 additions & 44 deletions grid-proxy/pkg/types/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,48 +115,48 @@ type Capacity struct {

// NodeFilter node filters
type NodeFilter struct {
Status []string `schema:"status,omitempty"`
FreeMRU *uint64 `schema:"free_mru,omitempty"`
FreeHRU *uint64 `schema:"free_hru,omitempty"`
FreeSRU *uint64 `schema:"free_sru,omitempty"`
TotalMRU *uint64 `schema:"total_mru,omitempty"`
TotalHRU *uint64 `schema:"total_hru,omitempty"`
TotalSRU *uint64 `schema:"total_sru,omitempty"`
TotalCRU *uint64 `schema:"total_cru,omitempty"`
Country *string `schema:"country,omitempty"`
CountryContains *string `schema:"country_contains,omitempty"`
City *string `schema:"city,omitempty"`
CityContains *string `schema:"city_contains,omitempty"`
Region *string `schema:"region,omitempty"`
FarmName *string `schema:"farm_name,omitempty"`
FarmNameContains *string `schema:"farm_name_contains,omitempty"`
FarmIDs []uint64 `schema:"farm_ids,omitempty"`
FreeIPs *uint64 `schema:"free_ips,omitempty"`
IPv4 *bool `schema:"ipv4,omitempty"`
IPv6 *bool `schema:"ipv6,omitempty"`
Domain *bool `schema:"domain,omitempty"`
Dedicated *bool `schema:"dedicated,omitempty"`
InDedicatedFarm *bool `schema:"in_dedicated_farm,omitempty"`
Rentable *bool `schema:"rentable,omitempty"`
OwnedBy *uint64 `schema:"owned_by,omitempty"`
Rented *bool `schema:"rented,omitempty"`
RentedBy *uint64 `schema:"rented_by,omitempty"`
RentableBy *uint64 `schema:"rentable_by,omitempty"` // rented by twin or rentable
AvailableFor *uint64 `schema:"available_for,omitempty"` // rented by twin or free
NodeID *uint64 `schema:"node_id,omitempty"`
NodeIDs []uint64 `schema:"node_ids,omitempty"`
TwinID *uint64 `schema:"twin_id,omitempty"`
CertificationType *string `schema:"certification_type,omitempty"`
HasGPU *bool `schema:"has_gpu,omitempty"`
NumGPU *uint64 `schema:"num_gpu,omitempty"`
GpuDeviceID *string `schema:"gpu_device_id,omitempty"`
GpuDeviceName *string `schema:"gpu_device_name,omitempty"`
GpuVendorID *string `schema:"gpu_vendor_id,omitempty"`
GpuVendorName *string `schema:"gpu_vendor_name,omitempty"`
GpuAvailable *bool `schema:"gpu_available,omitempty"`
Healthy *bool `schema:"healthy,omitempty"`
PriceMin *float64 `schema:"price_min,omitempty"`
PriceMax *float64 `schema:"price_max,omitempty"`
Excluded []uint64 `schema:"excluded,omitempty"`
HasIpv6 *bool `schema:"has_ipv6,omitempty"`
Status []string `schema:"status,omitempty"`
FreeMRU *uint64 `schema:"free_mru,omitempty"`
FreeHRU *uint64 `schema:"free_hru,omitempty"`
FreeSRU *uint64 `schema:"free_sru,omitempty"`
TotalMRU *uint64 `schema:"total_mru,omitempty"`
TotalHRU *uint64 `schema:"total_hru,omitempty"`
TotalSRU *uint64 `schema:"total_sru,omitempty"`
TotalCRU *uint64 `schema:"total_cru,omitempty"`
Country *string `schema:"country,omitempty"`
CountryContains *string `schema:"country_contains,omitempty"`
City *string `schema:"city,omitempty"`
CityContains *string `schema:"city_contains,omitempty"`
Region *string `schema:"region,omitempty"`
FarmName *string `schema:"farm_name,omitempty"`
FarmNameContains *string `schema:"farm_name_contains,omitempty"`
FarmIDs []uint64 `schema:"farm_ids,omitempty"`
FreeIPs *uint64 `schema:"free_ips,omitempty"`
IPv4 *bool `schema:"ipv4,omitempty"`
IPv6 *bool `schema:"ipv6,omitempty"`
Domain *bool `schema:"domain,omitempty"`
Dedicated *bool `schema:"dedicated,omitempty"`
InDedicatedFarm *bool `schema:"in_dedicated_farm,omitempty"`
Rentable *bool `schema:"rentable,omitempty"`
OwnedBy *uint64 `schema:"owned_by,omitempty"`
Rented *bool `schema:"rented,omitempty"`
RentedBy *uint64 `schema:"rented_by,omitempty"`
RentableOrRentedBy *uint64 `schema:"rentable_by,omitempty"` // rented by twin or rentable
AvailableFor *uint64 `schema:"available_for,omitempty"` // rented by twin or free
NodeID *uint64 `schema:"node_id,omitempty"`
NodeIDs []uint64 `schema:"node_ids,omitempty"`
TwinID *uint64 `schema:"twin_id,omitempty"`
CertificationType *string `schema:"certification_type,omitempty"`
HasGPU *bool `schema:"has_gpu,omitempty"`
NumGPU *uint64 `schema:"num_gpu,omitempty"`
GpuDeviceID *string `schema:"gpu_device_id,omitempty"`
GpuDeviceName *string `schema:"gpu_device_name,omitempty"`
GpuVendorID *string `schema:"gpu_vendor_id,omitempty"`
GpuVendorName *string `schema:"gpu_vendor_name,omitempty"`
GpuAvailable *bool `schema:"gpu_available,omitempty"`
Healthy *bool `schema:"healthy,omitempty"`
PriceMin *float64 `schema:"price_min,omitempty"`
PriceMax *float64 `schema:"price_max,omitempty"`
Excluded []uint64 `schema:"excluded,omitempty"`
HasIpv6 *bool `schema:"has_ipv6,omitempty"`
}
4 changes: 2 additions & 2 deletions grid-proxy/tests/queries/mock_client/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ func (n *Node) satisfies(f types.NodeFilter, data *DBData) bool {

renter, ok := data.NodeRentedBy[n.NodeID]

if f.RentableBy != nil &&
((ok && renter != *f.RentableBy) ||
if f.RentableOrRentedBy != nil &&
((ok && renter != *f.RentableOrRentedBy) ||
(!ok && !(data.Farms[n.FarmID].DedicatedFarm || len(data.NonDeletedContracts[n.NodeID]) == 0))) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion grid-proxy/tests/queries/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ var nodeFilterRandomValueGenerator = map[string]func(agg NodesAggregate) interfa
}
return &c
},
"RentableBy": func(agg NodesAggregate) interface{} {
"RentableOrRentedBy": func(agg NodesAggregate) interface{} {
c := agg.twins[rand.Intn(len(agg.twins))]
if flip(.2) && len(agg.nodeRenters) != 0 {
c = agg.nodeRenters[rand.Intn(len(agg.nodeRenters))]
Expand Down

0 comments on commit feca39e

Please sign in to comment.