Skip to content

Commit 55efbbb

Browse files
committed
Rolling back changes
1 parent 01cccd0 commit 55efbbb

5 files changed

Lines changed: 50 additions & 74 deletions

File tree

api/pkg/di/container.go

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import (
7474
type Container struct {
7575
projectID string
7676
db *gorm.DB
77-
yugaByteDB *gorm.DB
77+
dedicatedDB *gorm.DB
7878
version string
7979
app *fiber.App
8080
eventDispatcher *services.EventDispatcher
@@ -209,47 +209,38 @@ func (container *Container) GormLogger() gormLogger.Interface {
209209
)
210210
}
211211

212-
// YugaByteDB creates an instance of gorm.DB if it has not been created already
213-
func (container *Container) YugaByteDB() (db *gorm.DB) {
212+
// DedicatedDB creates an instance of gorm.DB if it has not been created already
213+
func (container *Container) DedicatedDB() (db *gorm.DB) {
214214
container.logger.Debug(fmt.Sprintf("creating %T", db))
215-
if container.yugaByteDB != nil {
216-
return container.yugaByteDB
215+
if container.dedicatedDB != nil {
216+
return container.dedicatedDB
217217
}
218-
//
219-
//config := &gorm.Config{}
220-
//if isLocal() {
221-
// config = &gorm.Config{Logger: container.GormLogger()}
222-
//}
223-
//
224-
//db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL_YUGABYTE")), config)
225-
//if err != nil {
226-
// container.logger.Fatal(err)
227-
//}
228-
//
229-
//if err = db.Use(tracing.NewPlugin()); err != nil {
230-
// container.logger.Fatal(stacktrace.Propagate(err, "cannot use GORM tracing plugin"))
231-
//}
232-
//
233-
//sql, err := db.DB()
234-
//if err != nil {
235-
// container.logger.Fatal(err)
236-
//}
237-
//
238-
//sql.SetMaxOpenConns(7)
239-
//sql.SetMaxIdleConns(3)
240-
//sql.SetConnMaxLifetime(time.Minute * 10)
241-
//
242-
//container.logger.Debug(fmt.Sprintf("Running migrations for yugabyte [%T]", db))
243-
//if err = db.AutoMigrate(&entities.Heartbeat{}); err != nil {
244-
// container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Heartbeat{})))
245-
//}
246-
//
247-
//if err = db.AutoMigrate(&entities.HeartbeatMonitor{}); err != nil {
248-
// container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.HeartbeatMonitor{})))
249-
//}
250-
//
251-
//container.yugaByteDB = db
252-
return container.yugaByteDB
218+
219+
config := &gorm.Config{}
220+
if isLocal() {
221+
config = &gorm.Config{Logger: container.GormLogger()}
222+
}
223+
224+
db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL_DEDICATED")), config)
225+
if err != nil {
226+
container.logger.Fatal(err)
227+
}
228+
229+
if err = db.Use(tracing.NewPlugin()); err != nil {
230+
container.logger.Fatal(stacktrace.Propagate(err, "cannot use GORM tracing plugin"))
231+
}
232+
233+
container.logger.Debug(fmt.Sprintf("Running migrations for yugabyte [%T]", db))
234+
if err = db.AutoMigrate(&entities.Heartbeat{}); err != nil {
235+
container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Heartbeat{})))
236+
}
237+
238+
if err = db.AutoMigrate(&entities.HeartbeatMonitor{}); err != nil {
239+
container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.HeartbeatMonitor{})))
240+
}
241+
242+
container.dedicatedDB = db
243+
return container.dedicatedDB
253244
}
254245

255246
// DB creates an instance of gorm.DB if it has not been created already
@@ -706,7 +697,7 @@ func (container *Container) HeartbeatMonitorRepository() (repository repositorie
706697
return repositories.NewGormHeartbeatMonitorRepository(
707698
container.Logger(),
708699
container.Tracer(),
709-
container.YugaByteDB(),
700+
container.DedicatedDB(),
710701
)
711702
}
712703

@@ -1303,7 +1294,7 @@ func (container *Container) HeartbeatRepository() repositories.HeartbeatReposito
13031294
return repositories.NewGormHeartbeatRepository(
13041295
container.Logger(),
13051296
container.Tracer(),
1306-
container.YugaByteDB(),
1297+
container.DedicatedDB(),
13071298
)
13081299
}
13091300

api/pkg/repositories/gorm_heartbeat_monitor_repository.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ func (repository *gormHeartbeatMonitorRepository) UpdateQueueID(ctx context.Cont
2727
ctx, span := repository.tracer.Start(ctx)
2828
defer span.End()
2929

30-
return stacktrace.NewError("not implemented")
31-
32-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
30+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
3331
defer cancel()
3432

3533
err := repository.db.
@@ -50,9 +48,7 @@ func (repository *gormHeartbeatMonitorRepository) Delete(ctx context.Context, us
5048
ctx, span := repository.tracer.Start(ctx)
5149
defer span.End()
5250

53-
return stacktrace.NewError("not implemented")
54-
55-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
51+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
5652
defer cancel()
5753

5854
err := repository.db.WithContext(ctx).
@@ -85,9 +81,7 @@ func (repository *gormHeartbeatMonitorRepository) Index(ctx context.Context, use
8581
ctx, span := repository.tracer.Start(ctx)
8682
defer span.End()
8783

88-
return nil, stacktrace.NewError("not implemented")
89-
90-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
84+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
9185
defer cancel()
9286

9387
query := repository.db.WithContext(ctx).Where("user_id = ?", userID).Where("owner = ?", owner)
@@ -105,9 +99,7 @@ func (repository *gormHeartbeatMonitorRepository) Store(ctx context.Context, hea
10599
ctx, span := repository.tracer.Start(ctx)
106100
defer span.End()
107101

108-
return stacktrace.NewError("not implemented")
109-
110-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
102+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
111103
defer cancel()
112104

113105
if err := repository.db.WithContext(ctx).Create(heartbeatMonitor).Error; err != nil {
@@ -123,9 +115,7 @@ func (repository *gormHeartbeatMonitorRepository) Load(ctx context.Context, user
123115
ctx, span := repository.tracer.Start(ctx)
124116
defer span.End()
125117

126-
return nil, stacktrace.NewError("not implemented")
127-
128-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
118+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
129119
defer cancel()
130120

131121
phone := new(entities.HeartbeatMonitor)
@@ -152,9 +142,7 @@ func (repository *gormHeartbeatMonitorRepository) Exists(ctx context.Context, us
152142
ctx, span := repository.tracer.Start(ctx)
153143
defer span.End()
154144

155-
return false, stacktrace.NewError("not implemented")
156-
157-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
145+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
158146
defer cancel()
159147

160148
var exists bool

api/pkg/repositories/gorm_heartbeat_repository.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package repositories
33
import (
44
"context"
55
"fmt"
6-
"time"
76

87
"github.com/pkg/errors"
98

@@ -37,9 +36,7 @@ func (repository *gormHeartbeatRepository) Last(ctx context.Context, userID enti
3736
ctx, span := repository.tracer.Start(ctx)
3837
defer span.End()
3938

40-
return nil, stacktrace.NewError("not implemented")
41-
42-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
39+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
4340
defer cancel()
4441

4542
heartbeat := new(entities.Heartbeat)
@@ -66,9 +63,7 @@ func (repository *gormHeartbeatRepository) Index(ctx context.Context, userID ent
6663
ctx, span := repository.tracer.Start(ctx)
6764
defer span.End()
6865

69-
return nil, stacktrace.NewError("not implemented")
70-
71-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
66+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
7267
defer cancel()
7368

7469
query := repository.db.WithContext(ctx).Where("user_id = ?", userID).Where("owner = ?", owner)
@@ -91,9 +86,7 @@ func (repository *gormHeartbeatRepository) Store(ctx context.Context, heartbeat
9186
ctx, span := repository.tracer.Start(ctx)
9287
defer span.End()
9388

94-
return stacktrace.NewError("not implemented")
95-
96-
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
89+
ctx, cancel := context.WithTimeout(ctx, dbOperationDuration)
9790
defer cancel()
9891

9992
if err := repository.db.WithContext(ctx).Create(heartbeat).Error; err != nil {

api/pkg/repositories/repository.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package repositories
22

3-
import "github.com/palantir/stacktrace"
3+
import (
4+
"time"
5+
6+
"github.com/palantir/stacktrace"
7+
)
48

59
// IndexParams parameters for indexing a database table
610
type IndexParams struct {
@@ -12,4 +16,6 @@ type IndexParams struct {
1216
const (
1317
// ErrCodeNotFound is thrown when an entity does not exist in storage
1418
ErrCodeNotFound = stacktrace.ErrorCode(1000)
19+
20+
dbOperationDuration = 1 * time.Second
1521
)

web/store/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ export const actions = {
303303
},
304304
})
305305

306-
try {
307-
await context.dispatch('getHeartbeat')
308-
} catch (e) {}
306+
await context.dispatch('getHeartbeat')
309307
context.commit('setThreads', response.data.data)
310308
},
311309

0 commit comments

Comments
 (0)