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

Project Viewset: Caching refactor #1902

Merged
merged 12 commits into from
Sep 24, 2020

Conversation

DavisRayM
Copy link
Contributor

@DavisRayM DavisRayM commented Sep 23, 2020

Changes / Features implemented

  • Fix an issue where the num_datasets value of a project was not updated when a form that used to belong to that form is transferred
  • Add reset_project_cache utility function
  • Re-sets project cache immediately after a new form is uploaded to a project
  • Clears project cache on Instance & XForm creation

Steps taken to verify this change does what is intended

  • Added / Updated tests

Side effects of implementing this change

  • Projects will have their caches re-set immediately after a form is uploaded
  • Projects cache will be cleared on XForm save & delete actions as well as on Instance save

Closes #1903

ivermac
ivermac previously approved these changes Sep 23, 2020
Copy link
Contributor

@ivermac ivermac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

"""
Clears and sets project cache
"""
from onadata.libs.serializers.project_serializer import ProjectSerializer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to assume we had to import here because of cyclic import error, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is here to avoid a cyclic import error

In some cases publish_form returns a dict containing an error message
as such we should only reset the project cache when an XForm is returned
@DavisRayM DavisRayM force-pushed the handle-stale-cache-in-project-endpoint branch from a053821 to c71a3b5 Compare September 24, 2020 06:56
@DavisRayM DavisRayM changed the title Re-set project cache on form upload [WIP] Re-set project cache on form upload Sep 24, 2020
@DavisRayM DavisRayM force-pushed the handle-stale-cache-in-project-endpoint branch from c71a3b5 to 90f2c19 Compare September 24, 2020 07:48
The Project viewset cache should be cleared if one of it's XForms or
Submissions have had an update to their data so that stale responses are
not returned
@DavisRayM DavisRayM force-pushed the handle-stale-cache-in-project-endpoint branch from 90f2c19 to cbc56e1 Compare September 24, 2020 07:53
Copy link
Member

pld commented Sep 24, 2020

Codacy Here is an overview of what got changed by this pull request:

Clones added
============
- onadata/apps/api/tests/viewsets/test_project_viewset.py  6
         

See the complete overview on Codacy

@DavisRayM DavisRayM changed the title [WIP] Re-set project cache on form upload Project Viewset: Caching refactor Sep 24, 2020
@DavisRayM DavisRayM merged commit 97b7b89 into master Sep 24, 2020
@DavisRayM DavisRayM deleted the handle-stale-cache-in-project-endpoint branch September 24, 2020 12:01
@DavisRayM DavisRayM mentioned this pull request Oct 12, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle stale project cache on retrieve for master-replica deployments
3 participants