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

Exploring embedded objects #1216

Closed
mahalakshme opened this issue Dec 5, 2023 · 4 comments
Closed

Exploring embedded objects #1216

mahalakshme opened this issue Dec 5, 2023 · 4 comments
Assignees

Comments

@mahalakshme
Copy link
Contributor

mahalakshme commented Dec 5, 2023

Motivation:

  • When a parent object, say individual is deleted, we would like registration location, entity approval status, observations, etc., to be deleted. This doesn't happen now, and we are deleting each child object and also we have missed in some places.
  • When an observation of an individual is updated, we would like the old observation that now doesn't have a parent to be deleted. This is not happening currently, and many orphan observations exist.
  • The above has led to increase of phone storage size to 8GB for some individuals but fresh sync occupies less than 200MB.
  • Doing the above manually without using embedded objects, might not be the efficient way to do it and bugs might creep in when we miss out as the app functionality increases(already we have missed out on many cases.)

Analysis:

According to realm documentation,

An embedded object inherits the lifecycle of its parent object and cannot exist as an independent Realm object. 
Realm automatically deletes embedded objects if their parent object is deleted or when overwritten by a new embedded object instance.

From an another realm documentation in github:

Such object do have to have a parent and they cannot have more than one parent.
  • So, the embedded objects suits our purpose but not all nested objects currently can be made embedded since in some cases, like concept can have multiple form elements as parents
  • Cant find a proper documentation where someone has migrated from nested to embedded realm objects.

Acceptance criteria:

  • Try out to make sure if embedded objects can/cannot have multiple parents
  • Make sure if our above purpose/motivation can be achieved
  • Come up with an estimate to do the needed code changes to make necessary models embedded
  • Come up with a plan and estimate to migrate existing users' data to embedded objects
  • Analyse the impact on our core usecases/design like sync, model functions, execution of existing rules, etc., and how it can be minimised.
  • Suggest if it is worth the effort and if it can be pursued as part of this release.
  • Also checkout if there are any better alternatives if not the above to achieve our purpose.
  • List out all objects that need to made embedded so that no garbage remains on users db
@mahalakshme mahalakshme converted this from a draft issue Dec 5, 2023
@mahalakshme mahalakshme moved this from In Analysis to In Analysis Review in Avni Product Dec 5, 2023
@mahalakshme mahalakshme moved this from In Analysis Review to Ready in Avni Product Dec 5, 2023
@petmongrels petmongrels moved this from Ready to In Progress in Avni Product Dec 6, 2023
@petmongrels petmongrels self-assigned this Dec 6, 2023
@petmongrels petmongrels moved this from In Progress to Ready in Avni Product Dec 8, 2023
@petmongrels petmongrels removed their assignment Dec 8, 2023
@petmongrels petmongrels moved this from Ready to In Progress in Avni Product Dec 12, 2023
@petmongrels petmongrels self-assigned this Dec 12, 2023
@petmongrels
Copy link
Contributor

petmongrels commented Dec 12, 2023

Observations

  • add embedded as following example

name: "Format", embedded: true, properties: { regex: "string", descriptionKey: "string" }

  • cannot query embedded objects directly from database (even though it has a schema name)

  • can query using the patch of embedded object

  • embedded object type can be used multiple times

  • migration is required like (in realm-embed model branch). schemaVersion number may have changed when the story is played.

  • deleting orphans can be done by changing the schema name. recommend doing it only for observations. others are small entities. The change is present in the spike branch.

  • Entities to update/migrate
    -- Format
    -- KeyValue
    -- StringKeyNumericValue
    -- Point
    -- ChecklistItemStatus
    -- Decision
    -- Observation
    -- VisitScheduleInterval

  • Not to be done because these are top level object, not referred by any other entity
    -- EntityQueue
    -- ConfigFile
    -- BeneficiaryModePin
    -- Extension
    -- UserDefinedIndividualProperty
    -- VisitScheduleConfig

  • Calls to load emebdded object types directly have to be removed (e.g. db.object(Observation.schema.name)). How to handle for the ones usage is found.
    -- Observation in PruneMedia (change code to do this per parent entity)

  • it takes about 30 seconds to migrate observations in large database. Loading white screen is shown, we should modify this to say that please do not close the screen.

@petmongrels petmongrels moved this from In Progress to Code Review Ready in Avni Product Dec 12, 2023
@petmongrels petmongrels moved this from Code Review Ready to In Progress in Avni Product Dec 13, 2023
@petmongrels
Copy link
Contributor

model changes pushed to realm-embed branch. it can be used when we play the actual story.

@petmongrels petmongrels moved this from In Progress to Code Review Ready in Avni Product Dec 13, 2023
@mahalakshme
Copy link
Contributor Author

@petmongrels EntityApprovalStatus, ProgramEncounter, ProgramEnrolment, Encounter, Individual Comment, Individual Group Subjects, etc., - these also can be made embedded right?

@petmongrels
Copy link
Contributor

petmongrels commented Dec 15, 2023 via email

@mahalakshme mahalakshme moved this from Code Review Ready to In Code Review in Avni Product Dec 20, 2023
@mahalakshme mahalakshme moved this from In Code Review to Done in Avni Product Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants