Skip to content
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

Change type of MongoDocuments to MutableMapping #87

Open
warownia1 opened this issue Mar 13, 2020 · 4 comments
Open

Change type of MongoDocuments to MutableMapping #87

warownia1 opened this issue Mar 13, 2020 · 4 comments

Comments

@warownia1
Copy link
Collaborator

By changing the type of MongoDocuments to slotted MutableMapping we can gain 2.3x performance boost at object creation and 4.7x less memory used compared to dict.
All of that at the cost of some boilerplate code implementing item access and manipulation methods.

@warownia1
Copy link
Collaborator Author

attr.s classes implementing MutableMapping are equally good

@warownia1 warownia1 moved this to Todo in Slivka 0.8 release Apr 9, 2024
@warownia1 warownia1 moved this from Todo to In Progress in Slivka 0.8 release Apr 9, 2024
@warownia1
Copy link
Collaborator Author

warownia1 commented Apr 12, 2024

MutableMappings which are not dicts seem to not work with mongomock.
Inserted items are stored as Python objects directly and not converted to json/bson
Collection.find() is unable to find them if filters are provided.

  • isolate issue into a separate minimal case
  • report issue to mongomock maintainers
  • test if the code works with the real mongo database (consider using actual mongo db for unit testing)

@warownia1
Copy link
Collaborator Author

Related issue:
mongomock/mongomock#886

@warownia1
Copy link
Collaborator Author

All tests green when using real mongo database in tests
Adjusting code to work with mongomock undoes all benefits gained from switching to slotted classes.

warownia1 added a commit that referenced this issue Apr 17, 2024
Mongomock does not work correctly with objects implementing Mapping
which are not dicts. This change adds dict conversion to objects
before saving which defeats the benefits of using slotted classes.
Fix #87
@warownia1 warownia1 moved this from In Progress to Stale in Slivka 0.8 release Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Stale
Development

No branches or pull requests

1 participant