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

Subgraph Best Practices 5 and 6 #825

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

marcusrein
Copy link
Member

Added Subgraph Best Practice 5 and Subgraph Best Practice 6 after peer review process was completed.

Updated formatting and added links to the bottom of each Subgraph Best Practice as well to improve congruency of this cookbook series.

Thanks!

@marcusrein marcusrein requested a review from a team as a code owner November 27, 2024 18:12
Copy link
Contributor

@idalithb idalithb left a comment

Choose a reason for hiding this comment

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

These are terrific! Great explanations @marcusrein 🔥

@@ -100,3 +100,17 @@ Note: Declared eth_calls can only be made in subgraphs with specVersion >= 1.2.0
## Conclusion

We can significantly improve indexing performance by minimizing or eliminating `eth_calls` in our subgraphs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
We can significantly improve indexing performance by minimizing or eliminating `eth_calls` in our subgraphs.
You can significantly improve indexing performance by minimizing or eliminating `eth_calls` in your subgraphs.


## Subgraph Best Practices 1-6

1. [Improve Query Speed with Subgraph Pruning](https://thegraph.com/docs/en/cookbook/pruning/)
Copy link
Contributor

Choose a reason for hiding this comment

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

All

Suggested change
1. [Improve Query Speed with Subgraph Pruning](https://thegraph.com/docs/en/cookbook/pruning/)
1. [Improve Query Speed with Subgraph Pruning](/cookbook/pruning/)

You should make this modification to all links
@benface correct me if I'm wrong here

Copy link
Contributor

Choose a reason for hiding this comment

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

Links that are within the docs*

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, because absolute links have the language (English) hardcoded in them, whereas relative ones keep the current language (and the href is copied over as-is to translated pages).

@@ -71,3 +71,17 @@ This will not only make our subgraph more efficient, but it will also unlock thr
Adopting the `@derivedFrom` directive in subgraphs effectively handles dynamically growing arrays, enhancing indexing efficiency and data retrieval.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Adopting the `@derivedFrom` directive in subgraphs effectively handles dynamically growing arrays, enhancing indexing efficiency and data retrieval.
Use the `@derivedFrom` directive in subgraphs to effectively manage dynamically growing arrays, enhancing indexing efficiency and data retrieval.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know you didn't edit this section, but adding it your PR since you edited these pages 😉

@@ -71,3 +71,17 @@ This will not only make our subgraph more efficient, but it will also unlock thr
Adopting the `@derivedFrom` directive in subgraphs effectively handles dynamically growing arrays, enhancing indexing efficiency and data retrieval.

To learn more detailed strategies to avoid large arrays, read this blog from Kevin Jones: [Best Practices in Subgraph Development: Avoiding Large Arrays](https://thegraph.com/blog/improve-subgraph-performance-avoiding-large-arrays/).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To learn more detailed strategies to avoid large arrays, read this blog from Kevin Jones: [Best Practices in Subgraph Development: Avoiding Large Arrays](https://thegraph.com/blog/improve-subgraph-performance-avoiding-large-arrays/).
For a more detailed explanation of strategies to avoid large arrays, check out Kevin Jones' blog: [Best Practices in Subgraph Development: Avoiding Large Arrays](https://thegraph.com/blog/improve-subgraph-performance-avoiding-large-arrays/).


## TLDR

Grafting is a powerful feature in subgraph development that allows you to build and deploy new subgraphs while reusing the indexed data from existing ones. This technique is particularly useful for quickly deploying hotfixes to address critical issues without the need to re-index the entire subgraph from scratch. By preserving historical data, grafting ensures minimal downtime and maintains continuity in data services.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Grafting is a powerful feature in subgraph development that allows you to build and deploy new subgraphs while reusing the indexed data from existing ones. This technique is particularly useful for quickly deploying hotfixes to address critical issues without the need to re-index the entire subgraph from scratch. By preserving historical data, grafting ensures minimal downtime and maintains continuity in data services.
## TLDR
Grafting is a powerful feature in subgraph development that allows you to build and deploy new subgraphs while reusing the indexed data from existing ones.
### Overview
This feature enables quick deployment of hotfixes for critical issues, eliminating the need to re-index the entire subgraph from scratch. By preserving historical data, grafting minimizes downtime and ensures continuity in data services.

To break up for quick readability 😃


## Why Timeseries and Aggregations Are a Best Practice

1. Improved Indexing Time • Less Data to Load: Mappings handle less data since raw data points are stored as immutable timeseries entities. • Database-Managed Aggregations: Aggregations are automatically computed by the database, reducing the workload on the mappings.
Copy link
Contributor

Choose a reason for hiding this comment

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

Spacing issue that's distorting the formatting. I think the bullet point are suppose to be below the numbers, right?

- first
- last

The arg in @aggregate can be:
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it should be a subheading

- A field name from the timeseries entity.
- An expression using fields and constants.

Examples of Aggregation Expressions:
Copy link
Contributor

Choose a reason for hiding this comment

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

This also seems like a subheading


### Important Considerations

- Immutable Data: Timeseries data cannot be altered once written, ensuring data integrity and simplifying indexing.
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be useful to place this closer to the top bc it strikes me as a warning


## How to Implement Timeseries and Aggregations

### Defining Timeseries Entities
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a hierarchy to all the headings underneath? They're all level 3 headings, so just double checking 😄

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.

3 participants