mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-22 00:03:58 +01:00
Wire through a flag so that we can track when installations come from tests, and delete those from the DB more aggressively
This commit is contained in:
parent
449a4d0000
commit
f3727dbeff
@ -216,11 +216,12 @@ func (s *Server) apiRegisterHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
userId := getRequiredQueryParam(r, "user_id")
|
||||
deviceId := getRequiredQueryParam(r, "device_id")
|
||||
isIntegrationTestDevice := getOptionalQueryParam(r, "is_integration_test_device", false) == "true"
|
||||
|
||||
existingDevicesCount, err := s.db.CountDevicesForUser(r.Context(), userId)
|
||||
checkGormError(err)
|
||||
fmt.Printf("apiRegisterHandler: existingDevicesCount=%d\n", existingDevicesCount)
|
||||
if err := s.db.CreateDevice(r.Context(), &shared.Device{UserId: userId, DeviceId: deviceId, RegistrationIp: getRemoteAddr(r), RegistrationDate: time.Now()}); err != nil {
|
||||
if err := s.db.CreateDevice(r.Context(), &shared.Device{UserId: userId, DeviceId: deviceId, RegistrationIp: getRemoteAddr(r), RegistrationDate: time.Now(), IsIntegrationTestDevice: isIntegrationTestDevice}); err != nil {
|
||||
checkGormError(err)
|
||||
}
|
||||
|
||||
|
@ -82,9 +82,9 @@ func getRequiredQueryParam(r *http.Request, queryParam string) string {
|
||||
return val
|
||||
}
|
||||
|
||||
func getOptionalQueryParam(r *http.Request, queryParam string, isTestEnvironment bool) string {
|
||||
func getOptionalQueryParam(r *http.Request, queryParam string, isRequiredInTestEnvironment bool) string {
|
||||
val := r.URL.Query().Get(queryParam)
|
||||
if val == "" && isTestEnvironment {
|
||||
if val == "" && isRequiredInTestEnvironment {
|
||||
panic(fmt.Sprintf("request to %s is missing optional query param=%#v that is required in test environments", r.URL, queryParam))
|
||||
}
|
||||
return val
|
||||
|
@ -83,7 +83,11 @@ func Setup(userSecret string, isOffline bool) error {
|
||||
return nil
|
||||
}
|
||||
ctx := hctx.MakeContext()
|
||||
_, err = ApiGet(ctx, "/api/v1/register?user_id="+data.UserId(userSecret)+"&device_id="+config.DeviceId)
|
||||
registerPath := "/api/v1/register?user_id=" + data.UserId(userSecret) + "&device_id=" + config.DeviceId
|
||||
if os.Getenv("HISHTORY_TEST") != "" {
|
||||
registerPath += "&is_integration_test_device=true"
|
||||
}
|
||||
_, err = ApiGet(ctx, registerPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to register device with backend: %w", err)
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ type Device struct {
|
||||
// david@daviddworken.com and I can clear it from your device entries.
|
||||
RegistrationIp string `json:"registration_ip"`
|
||||
RegistrationDate time.Time `json:"registration_date"`
|
||||
// Test devices, that should be aggressively cleaned from the DB
|
||||
// TODO: Clean these from the DB
|
||||
IsIntegrationTestDevice bool `json:"is_integration_test_device"`
|
||||
}
|
||||
|
||||
// Represents a request to get all history entries from a given device. Used as part of bootstrapping
|
||||
|
Loading…
Reference in New Issue
Block a user