-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): reduce size of queries sent to MongoDB (#550)
- Loading branch information
Showing
28 changed files
with
318 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
package mongodoc | ||
|
||
import "github.com/reearth/reearthx/mongox" | ||
|
||
func NewComsumer[T Model[U], U any]() *mongox.SliceFuncConsumer[T, U] { | ||
return mongox.NewSliceFuncConsumer(func(d T) (U, error) { | ||
return d.Model() | ||
}) | ||
} | ||
import ( | ||
"github.com/reearth/reearthx/mongox" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
type Model[T any] interface { | ||
Model() (T, error) | ||
} | ||
|
||
type Consumer[T, K any] struct { | ||
Result []K | ||
c mongox.SimpleConsumer[T] | ||
} | ||
|
||
func NewConsumer[T Model[U], U any](filter func(U) bool) *Consumer[T, U] { | ||
var c *Consumer[T, U] | ||
c = &Consumer[T, U]{ | ||
c: mongox.SimpleConsumer[T](func(d T) error { | ||
e, err := d.Model() | ||
if err != nil { | ||
return err | ||
} | ||
if filter == nil || filter(e) { | ||
c.Result = append(c.Result, e) | ||
} | ||
return nil | ||
}), | ||
} | ||
return c | ||
} | ||
|
||
func (s *Consumer[T, K]) Consume(raw bson.Raw) error { | ||
return s.c.Consume(raw) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.