Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MongoEngine/mongoengine into fix_…
Browse files Browse the repository at this point in the history
…performance_issue_count
  • Loading branch information
bagerard committed Dec 16, 2023
2 parents 5b53314 + ff701bd commit bf827d7
Show file tree
Hide file tree
Showing 70 changed files with 2,269 additions and 1,273 deletions.
91 changes: 53 additions & 38 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ on:
push:
branches:
- master
# Manual trigger from Action page
workflow_dispatch:
# release tags
create:
tags:
- 'v[0-9]+\.[0-9]+\.[0-9]+*'
env:
MONGODB_3_6: 3.6.14
MONGODB_4_0: 4.0.23
MONGODB_4_2: 4.2
MONGODB_3_6: 3.6.23
MONGODB_4_0: 4.0.28
MONGODB_4_4: 4.4
MONGODB_5_0: "5.0"
MONGODB_6_0: "6.0"
MONGODB_7_0: "7.0"

PYMONGO_3_4: 3.4
PYMONGO_3_6: 3.6
PYMONGO_3_9: 3.9
PYMONGO_3_11: 3.11
PYMONGO_3_12: 3.12
PYMONGO_4_0: 4.0
PYMONGO_4_3: 4.3.2
PYMONGO_4_4: 4.4.1
PYMONGO_4_6: 4.6.0

MAIN_PYTHON_VERSION: 3.7

Expand All @@ -29,40 +38,53 @@ jobs:
# which runs pre-configured linter & autoformatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: '3.9'
check-latest: true
- run: bash .github/workflows/install_ci_python_dep.sh
- run: pre-commit run -a

test:
# Test suite run against recent python versions
# and against a few combination of MongoDB and pymongo
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, pypy3]
python-version: [3.7, 3.8, 3.9, "3.10", 3.11, pypy3.9]
MONGODB: [$MONGODB_4_0]
PYMONGO: [$PYMONGO_3_11]
include:
- python-version: 3.7
MONGODB: $MONGODB_3_6
PYMONGO: $PYMONGO_3_9
- python-version: 3.7
MONGODB: $MONGODB_4_2
PYMONGO: $PYMONGO_3_6
- python-version: 3.7
- python-version: 3.8
MONGODB: $MONGODB_4_4
PYMONGO: $PYMONGO_3_11
- python-version: 3.9
MONGODB: $MONGODB_4_4
PYMONGO: $PYMONGO_3_12
- python-version: "3.10"
MONGODB: $MONGODB_4_4
PYMONGO: $PYMONGO_4_0
- python-version: "3.11"
MONGODB: $MONGODB_5_0
PYMONGO: $PYMONGO_4_3
- python-version: "3.11"
MONGODB: $MONGODB_6_0
PYMONGO: $PYMONGO_4_4
- python-version: "3.11"
MONGODB: $MONGODB_7_0
PYMONGO: $PYMONGO_4_6
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: install mongo and ci dependencies
run: |
bash .github/workflows/install_mongo.sh ${{ matrix.MONGODB }}
Expand All @@ -84,11 +106,12 @@ jobs:
# to avoid that it breaks when new releases are being created
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.7
check-latest: true
- name: install python dep
run: |
pip install -e .
Expand All @@ -98,46 +121,38 @@ jobs:
cd docs
make html-readthedocs
build-n-publish-dummy:
build-dryrun:
runs-on: ubuntu-latest
needs: [linting, test, build_doc_dryrun]
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@master
- name: Set up Python 3.7
uses: actions/setup-python@v1
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.9
check-latest: true
- name: build dummy wheel for test-pypi
run: |
pip install wheel
python setup.py egg_info -b ".dev`date '+%Y%m%d%H%M%S'`" build sdist bdist_wheel
# - name: publish test-pypi
# # Although working and recommended, test-pypi has a limit
# # in the size of projects so it's better to avoid publishing
# # until there is a way to garbage collect these dummy releases
# uses: pypa/gh-action-pypi-publish@master
# with:
# password: ${{ secrets.test_pypi_token }}
# repository_url: https://test.pypi.org/legacy/
python setup.py sdist bdist_wheel
build-n-publish:
runs-on: ubuntu-latest
needs: [linting, test, build_doc_dryrun, build-n-publish-dummy]
needs: [linting, test, build_doc_dryrun, build-dryrun]
if: github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@master
- name: Set up Python 3.7
uses: actions/setup-python@v1
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.9
check-latest: true
# todo separate build from publish
# https://stackoverflow.com/questions/59349905/which-properties-does-github-event-in-a-github-workflow-have
- name: build dummy wheel for test-pypi
run: |
pip install wheel
python setup.py sdist bdist_wheel
- name: publish pypi
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.pypi_token }}
6 changes: 6 additions & 0 deletions .github/workflows/install_mongo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ if [[ "$MONGODB" == *"4.2"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
elif [[ "$MONGODB" == *"4.4"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
elif [[ "$MONGODB" == *"5.0"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
elif [[ "$MONGODB" == *"6.0"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu1804-v${MONGODB}-latest
elif [[ "$MONGODB" == *"7.0"* ]]; then
mongo_build=mongodb-linux-x86_64-ubuntu2004-v${MONGODB}-latest
fi

wget http://fastdl.mongodb.org/linux/$mongo_build.tgz
Expand Down
14 changes: 8 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/ambv/black
rev: 21.4b2
rev: 23.9.1
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.1
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- importlib_metadata<5
- repo: https://github.com/asottile/pyupgrade
rev: v2.14.0
rev: v3.14.0
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/pycqa/isort
rev: 5.8.0
rev: 5.12.0
hooks:
- id: isort
4 changes: 4 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,7 @@ that much better:
* Stankiewicz Mateusz (https://github.com/mas15)
* Felix Schultheiß (https://github.com/felix-smashdocs)
* Jan Stein (https://github.com/janste63)
* Timothé Perez (https://github.com/AchilleAsh)
* oleksandr-l5 (https://github.com/oleksandr-l5)
* Ido Shraga (https://github.com/idoshr)
* Terence Honles (https://github.com/terencehonles)
10 changes: 8 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ MongoEngine
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black

.. image:: https://pepy.tech/badge/mongoengine/month
:target: https://pepy.tech/project/mongoengine

.. image:: https://img.shields.io/pypi/v/mongoengine.svg
:target: https://pypi.python.org/pypi/mongoengine

About
=====
MongoEngine is a Python Object-Document Mapper for working with MongoDB.
Expand All @@ -25,10 +31,10 @@ an `API reference <https://mongoengine-odm.readthedocs.io/apireference.html>`_.

Supported MongoDB Versions
==========================
MongoEngine is currently tested against MongoDB v3.4, v3.6 and v4.0. Future versions
MongoEngine is currently tested against MongoDB v3.6, v4.0, v4.4, v5.0, v6.0 and v7.0. Future versions
should be supported as well, but aren't actively tested at the moment. Make
sure to open an issue or submit a pull request if you experience any problems
with MongoDB version > 4.0.
with a more recent MongoDB versions.

Installation
============
Expand Down
32 changes: 16 additions & 16 deletions benchmarks/test_basic_doc_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
StringField,
)

mongoengine.connect(db="mongoengine_benchmark_test")
mongoengine.connect(db="mongoengine_benchmark_test", w=1)


def timeit(f, n=10000):
Expand All @@ -38,34 +38,34 @@ def init_book():
author_email="[email protected]",
)

print("Doc initialization: %.3fus" % (timeit(init_book, 1000) * 10 ** 6))
print("Doc initialization: %.3fus" % (timeit(init_book, 1000) * 10**6))

b = init_book()
print("Doc getattr: %.3fus" % (timeit(lambda: b.name, 10000) * 10 ** 6))
print("Doc getattr: %.3fus" % (timeit(lambda: b.name, 10000) * 10**6))

print(
"Doc setattr: %.3fus"
% (timeit(lambda: setattr(b, "name", "New name"), 10000) * 10 ** 6) # noqa B010
% (timeit(lambda: setattr(b, "name", "New name"), 10000) * 10**6) # noqa B010
)

print("Doc to mongo: %.3fus" % (timeit(b.to_mongo, 1000) * 10 ** 6))
print("Doc to mongo: %.3fus" % (timeit(b.to_mongo, 1000) * 10**6))

print("Doc validation: %.3fus" % (timeit(b.validate, 1000) * 10 ** 6))
print("Doc validation: %.3fus" % (timeit(b.validate, 1000) * 10**6))

def save_book():
b._mark_as_changed("name")
b._mark_as_changed("tags")
b.save()

print("Save to database: %.3fus" % (timeit(save_book, 100) * 10 ** 6))
print("Save to database: %.3fus" % (timeit(save_book, 100) * 10**6))

son = b.to_mongo()
print(
"Load from SON: %.3fus" % (timeit(lambda: Book._from_son(son), 1000) * 10 ** 6)
"Load from SON: %.3fus" % (timeit(lambda: Book._from_son(son), 1000) * 10**6)
)

print(
"Load from database: %.3fus" % (timeit(lambda: Book.objects[0], 100) * 10 ** 6)
"Load from database: %.3fus" % (timeit(lambda: Book.objects[0], 100) * 10**6)
)

def create_and_delete_book():
Expand All @@ -75,7 +75,7 @@ def create_and_delete_book():

print(
"Init + save to database + delete: %.3fms"
% (timeit(create_and_delete_book, 10) * 10 ** 3)
% (timeit(create_and_delete_book, 10) * 10**3)
)


Expand All @@ -101,9 +101,9 @@ def init_company():
)

company = init_company()
print("Big doc to mongo: %.3fms" % (timeit(company.to_mongo, 100) * 10 ** 3))
print("Big doc to mongo: %.3fms" % (timeit(company.to_mongo, 100) * 10**3))

print("Big doc validation: %.3fms" % (timeit(company.validate, 1000) * 10 ** 3))
print("Big doc validation: %.3fms" % (timeit(company.validate, 1000) * 10**3))

company.save()

Expand All @@ -112,17 +112,17 @@ def save_company():
company._mark_as_changed("contacts")
company.save()

print("Save to database: %.3fms" % (timeit(save_company, 100) * 10 ** 3))
print("Save to database: %.3fms" % (timeit(save_company, 100) * 10**3))

son = company.to_mongo()
print(
"Load from SON: %.3fms"
% (timeit(lambda: Company._from_son(son), 100) * 10 ** 3)
% (timeit(lambda: Company._from_son(son), 100) * 10**3)
)

print(
"Load from database: %.3fms"
% (timeit(lambda: Company.objects[0], 100) * 10 ** 3)
% (timeit(lambda: Company.objects[0], 100) * 10**3)
)

def create_and_delete_company():
Expand All @@ -132,7 +132,7 @@ def create_and_delete_company():

print(
"Init + save to database + delete: %.3fms"
% (timeit(create_and_delete_company, 10) * 10 ** 3)
% (timeit(create_and_delete_company, 10) * 10**3)
)


Expand Down
Loading

0 comments on commit bf827d7

Please sign in to comment.