Refactoring

Why refactor?

Refactoring is the process of changing the data model and the graph.

There are three reasons why you would refactor:

  • The graph as modeled does not answer all of the use cases.

  • A new use case has come up that you must account for in your data model.

  • The Cypher for the use cases does not perform optimally, especially when the graph scales

Steps for refactoring

To refactor a graph data model and a graph, you must:

  1. Design the new data model.

  2. Write Cypher code to transform the existing graph to implement the new data model.

  3. Retest all use cases, possibly with updated Cypher code.

Check your understanding

1. Why refactor?

Why do you refactor a graph data model and graph?

  • ✓ Any of the use cases cannot be answered by the graph.

  • ✓ Another use case has been created that needs to be accounted for.

  • ❏ Some data in the graph needs to be updated.

  • ✓ The data model does not scale.

Hint

There are three main reasons you refactor the data model and the graph.

Solution

You may want to refactor if any of the use cases cannot be answered, or if another use case has been added. It it also important to ensure that the data model scales effectively and still provides data in a timely fashion.

As long as the data model stays the same, you do not need to refactor the graph specifically when updating or adding new data.

Summary

In this lesson, you learned why you refactor a graph and the steps for refactoring. In the next lesson, you will learn labels are important in the graph data model and how you can refactor a graph to add labels.