-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: avoid payload limitation [MD-266] #9164
Changes from all commits
c89c1a3
0a54cd9
e24b818
3d969fb
58721cc
3d54e81
4b8be7e
48cf0c9
a4ce2c2
25791e9
1f126e0
f6bf719
8d36ef3
a5c859c
1ebf8a9
196f78a
51ce188
1732752
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,22 +51,27 @@ type ModelMsg struct { | |
} | ||
|
||
// SeqNum gets the SeqNum from a ModelMsg. | ||
func (pm *ModelMsg) SeqNum() int64 { | ||
return pm.Seq | ||
func (mm *ModelMsg) SeqNum() int64 { | ||
return mm.Seq | ||
} | ||
|
||
// GetID gets the ID from a ModelMsg. | ||
func (mm *ModelMsg) GetID() int { | ||
return mm.ID | ||
} | ||
|
||
// UpsertMsg creates a model stream upsert message. | ||
func (pm *ModelMsg) UpsertMsg() stream.UpsertMsg { | ||
return stream.UpsertMsg{ | ||
func (mm *ModelMsg) UpsertMsg() *stream.UpsertMsg { | ||
return &stream.UpsertMsg{ | ||
JSONKey: ModelsUpsertKey, | ||
Msg: pm, | ||
Msg: mm, | ||
} | ||
} | ||
|
||
// DeleteMsg creates a model stream delete message. | ||
func (pm *ModelMsg) DeleteMsg() stream.DeleteMsg { | ||
deleted := strconv.FormatInt(int64(pm.ID), 10) | ||
return stream.DeleteMsg{ | ||
func (mm *ModelMsg) DeleteMsg() *stream.DeleteMsg { | ||
deleted := strconv.Itoa(mm.ID) | ||
return &stream.DeleteMsg{ | ||
Key: ModelsDeleteKey, | ||
Deleted: deleted, | ||
} | ||
|
@@ -152,7 +157,7 @@ func ModelCollectStartupMsgs( | |
} | ||
missing, appeared, err := processQuery(ctx, createQuery, spec.Since, known, "m") | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("processing known: %w", err) | ||
} | ||
|
||
// step 2: hydrate appeared IDs into full ModelMsgs | ||
|
@@ -163,14 +168,14 @@ func ModelCollectStartupMsgs( | |
query = permFilterQuery(query, accessScopes) | ||
} | ||
err := query.Scan(ctx, &modelMsgs) | ||
if err != nil && errors.Cause(err) != sql.ErrNoRows { | ||
if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||
log.Errorf("error: %v\n", err) | ||
return nil, err | ||
} | ||
} | ||
|
||
// step 3: emit deletions and updates to the client | ||
out = append(out, stream.DeleteMsg{ | ||
out = append(out, &stream.DeleteMsg{ | ||
Key: ModelsDeleteKey, | ||
Deleted: missing, | ||
}) | ||
|
@@ -246,3 +251,19 @@ func ModelMakePermissionFilter(ctx context.Context, user model.User) (func(*Mode | |
}, nil | ||
} | ||
} | ||
|
||
// ModelMakeHydrator returns a function that gets properties of a model by | ||
// its id. | ||
func ModelMakeHydrator() func(*ModelMsg) (*ModelMsg, error) { | ||
return func(msg *ModelMsg) (*ModelMsg, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments here as the other hydrators |
||
var saturatedMsg ModelMsg | ||
query := db.Bun().NewSelect().Model(&saturatedMsg).Where("id = ?", msg.GetID()) | ||
err := query.Scan(context.Background(), &saturatedMsg) | ||
if err != nil && errors.Is(err, sql.ErrNoRows) { | ||
return nil, err | ||
} else if err != nil { | ||
return nil, fmt.Errorf("error in model hydrator: %w", err) | ||
} | ||
return &saturatedMsg, nil | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,18 +57,23 @@ func (pm *ProjectMsg) SeqNum() int64 { | |
return pm.Seq | ||
} | ||
|
||
// GetID gets the ID from a ProjectMsg. | ||
func (pm *ProjectMsg) GetID() int { | ||
return pm.ID | ||
} | ||
|
||
// UpsertMsg creates a Project stream upsert message. | ||
func (pm *ProjectMsg) UpsertMsg() stream.UpsertMsg { | ||
return stream.UpsertMsg{ | ||
func (pm *ProjectMsg) UpsertMsg() *stream.UpsertMsg { | ||
return &stream.UpsertMsg{ | ||
JSONKey: ProjectsUpsertKey, | ||
Msg: pm, | ||
} | ||
} | ||
|
||
// DeleteMsg creates a Project stream delete message. | ||
func (pm *ProjectMsg) DeleteMsg() stream.DeleteMsg { | ||
deleted := strconv.FormatInt(int64(pm.ID), 10) | ||
return stream.DeleteMsg{ | ||
func (pm *ProjectMsg) DeleteMsg() *stream.DeleteMsg { | ||
deleted := strconv.Itoa(pm.ID) | ||
return &stream.DeleteMsg{ | ||
Key: ProjectsDeleteKey, | ||
Deleted: deleted, | ||
} | ||
|
@@ -150,7 +155,7 @@ func ProjectCollectStartupMsgs( | |
} | ||
missing, appeared, err := processQuery(ctx, createQuery, spec.Since, known, "p") | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("processing known: %w", err) | ||
} | ||
|
||
// step 2: hydrate appeared IDs into full ProjectMsgs | ||
|
@@ -161,14 +166,14 @@ func ProjectCollectStartupMsgs( | |
query = permFilterQuery(query, accessScopes) | ||
} | ||
err := query.Scan(ctx, &projMsgs) | ||
if err != nil && errors.Cause(err) != sql.ErrNoRows { | ||
if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||
log.Errorf("error: %v\n", err) | ||
return nil, err | ||
} | ||
} | ||
|
||
// step 3: emit deletions and updates to the client | ||
out = append(out, stream.DeleteMsg{ | ||
out = append(out, &stream.DeleteMsg{ | ||
Key: ProjectsDeleteKey, | ||
Deleted: missing, | ||
}) | ||
|
@@ -233,3 +238,19 @@ func ProjectMakePermissionFilter(ctx context.Context, user model.User) (func(*Pr | |
}, nil | ||
} | ||
} | ||
|
||
// ProjectMakeHydrator returns a function that gets properties of a project by | ||
// its id. | ||
func ProjectMakeHydrator() func(*ProjectMsg) (*ProjectMsg, error) { | ||
return func(msg *ProjectMsg) (*ProjectMsg, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments here as the others |
||
var saturatedMsg ProjectMsg | ||
query := db.Bun().NewSelect().Model(&saturatedMsg).Where("project_msg.id = ?", msg.GetID()) | ||
err := query.Scan(context.Background(), &saturatedMsg) | ||
if err != nil && errors.Is(err, sql.ErrNoRows) { | ||
return nil, err | ||
} else if err != nil { | ||
return nil, fmt.Errorf("error in project hydrator: %w", err) | ||
} | ||
return &saturatedMsg, nil | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ const ( | |
// otherwise, returns the MarshallableMsg that the streamer sends. | ||
func testPrepareFunc(i stream.MarshallableMsg) interface{} { | ||
switch msg := i.(type) { | ||
case stream.UpsertMsg: | ||
case *stream.UpsertMsg: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious, why do we need to change to pointer types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The type of |
||
switch typedMsg := msg.Msg.(type) { | ||
case *ProjectMsg: | ||
return fmt.Sprintf( | ||
|
@@ -50,7 +50,7 @@ func testPrepareFunc(i stream.MarshallableMsg) interface{} { | |
typedMsg.WorkspaceID, | ||
) | ||
} | ||
case stream.DeleteMsg: | ||
case *stream.DeleteMsg: | ||
return fmt.Sprintf("key: %s, deleted: %s", msg.Key, msg.Deleted) | ||
case stream.SyncMsg: | ||
return fmt.Sprintf("key: %s, sync_id: %s, complete: %t", syncKey, msg.SyncID, msg.Complete) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is there a reason we aren't wrapping this error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will wrap it.