Skip to content

Commit

Permalink
test: improve performance by disabling audit log from batch handling
Browse files Browse the repository at this point in the history
KK-1113
  • Loading branch information
nikomakela committed Dec 27, 2024
1 parent 8f7792e commit 8a73c61
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
84 changes: 42 additions & 42 deletions children/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,29 +1520,29 @@ def test_children_pagination_cursor_works_the_same_with_offset_and_after(
with disable_auditlog():
ChildWithGuardianFactory.create_batch(110, project=project)

offset = (page - 1) * limit
executed_with_offset = project_user_api_client.execute(
query,
variables={
"projectId": get_global_id(project),
"limit": limit,
"offset": offset,
},
)

# NOTE: There will be 1 result less in the after-query,
# because the after-parameter is read from the first result
# and the cursor set in after, is not included in the result set.
first = limit - 1
after = executed_with_offset["data"]["children"]["edges"][0]["cursor"]
executed_with_after = project_user_api_client.execute(
query,
variables={
"projectId": get_global_id(project),
"first": first,
"after": after,
},
)
offset = (page - 1) * limit
executed_with_offset = project_user_api_client.execute(
query,
variables={
"projectId": get_global_id(project),
"limit": limit,
"offset": offset,
},
)

# NOTE: There will be 1 result less in the after-query,
# because the after-parameter is read from the first result
# and the cursor set in after, is not included in the result set.
first = limit - 1
after = executed_with_offset["data"]["children"]["edges"][0]["cursor"]
executed_with_after = project_user_api_client.execute(
query,
variables={
"projectId": get_global_id(project),
"first": first,
"after": after,
},
)

assert len(executed_with_after["data"]["children"]["edges"]) == first
assert (
Expand All @@ -1568,28 +1568,28 @@ def test_children_pagination_cursor_generation(
with disable_auditlog():
ChildWithGuardianFactory.create_batch(total_count, project=project)

query = """
query Children($projectId: ID!, $limit: Int, $offset: Int) {
children(projectId: $projectId, limit: $limit, offset: $offset) {
edges {
cursor
query = """
query Children($projectId: ID!, $limit: Int, $offset: Int) {
children(projectId: $projectId, limit: $limit, offset: $offset) {
edges {
cursor
}
}
}
}
""" # noqa: E501

executed_with_offset = project_user_api_client.execute(
query,
variables={
"projectId": get_global_id(project),
"limit": limit,
"offset": offset,
},
)
""" # noqa: E501

executed_with_offset = project_user_api_client.execute(
query,
variables={
"projectId": get_global_id(project),
"limit": limit,
"offset": offset,
},
)

cursors = [
edge["cursor"] for edge in executed_with_offset["data"]["children"]["edges"]
]
cursors = [
edge["cursor"] for edge in executed_with_offset["data"]["children"]["edges"]
]
assert len(cursors) == limit

expected_cursors = [
Expand Down
12 changes: 7 additions & 5 deletions users/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest import mock

import pytest
from auditlog.context import disable_auditlog
from django.core.management import call_command
from django.core.management.base import CommandError
from django.utils import timezone
Expand Down Expand Up @@ -214,11 +215,12 @@ def test_command_obsolete_handled_users_with_batch_size(
Test that "-o" or "--obsolete_handled_users" argument
marks the handled users as obsolete with different batch sizes.
"""
GuardianFactory.create_batch(
size=guardian_count,
user__date_joined=timezone.now() - timedelta(days=1),
user__is_obsolete=False,
)
with disable_auditlog():
GuardianFactory.create_batch(
size=guardian_count,
user__date_joined=timezone.now() - timedelta(days=1),
user__is_obsolete=False,
)
assert Guardian.objects.count() == guardian_count
assert Guardian.objects.filter(user__is_obsolete=False).count() == guardian_count

Expand Down

0 comments on commit 8a73c61

Please sign in to comment.