Docs
Arama⌘ K
  • Ana sayfa
  • Graph Hakkında
  • Desteklenen Ağlar
  • Protocol Contracts
  • Subgraph'ler
    • Substream'ler
      • Token API
        • AI Suite
          • Endeksleme
            • Kaynaklar
              Subgraph'ler > En İyi Uygulamalar

              2 dakika

              Subgraph Örnek Uygulamalar 2 - @derivedFrom Kullanarak Endeksleme ve Sorgu Performansını İyileştirin

              Özet

              Arrays in your schema can really slow down a Subgraph’s performance as they grow beyond thousands of entries. If possible, the @derivedFrom directive should be used when using arrays as it prevents large arrays from forming, simplifies handlers, and reduces the size of individual entities, improving indexing speed and query performance significantly.

              @derivedFrom Yönergesi Nasıl Kullanılır

              Şemanızdaki dizinin ardına @derivedFrom yönergesini eklemeniz yeterlidir. Örnek:

              1comments: [Comment!]! @derivedFrom(field: "post")

              @derivedFrom creates efficient one-to-many relationships, enabling an entity to dynamically associate with multiple related entities based on a field in the related entity. This approach removes the need for both sides of the relationship to store duplicate data, making the Subgraph more efficient.

              @derivedFrom’ın Örnek Kullanımı

              Dinamik olarak büyüyen dizilere örnek olarak, bir “Post”un (gönderinin) birçok “Comment” (yorum) içerebileceği bir blog platformu verilebilir.

              Post ve Comment olmak üzere iki varlıkla başlayalım

              Optimizasyon olmadan, bunu bir dizi ile şu şekilde uygulayabilirsiniz:

              1type Post @entity {2  id: Bytes!3  title: String!4  content: String!5  comments: [Comment!]!6}78type Comment @entity {9  id: Bytes!10  content: String!11}

              Bu tür diziler, fiilen, ilişkinin “Post” tarafında fazladan “Comments” verisi depolar.

              @derivedFrom kullanarak optimize edilmiş bir sürüm şu şekilde görünür:

              1type Post @entity {2  id: Bytes!3  title: String!4  content: String!5  comments: [Comment!]! @derivedFrom(field: "post")6}78type Comment @entity {9  id: Bytes!10  content: String!11  post: Post!12}

              Sadece @derivedFrom yönergesini ekleyerek bu şema, ilişkinin “Post” tarafında değil, yalnızca “Comments” tarafında “Comments” verilerini depolamış olur. Diziler bireysel satırlara yayıldığı için önemli ölçüde genişleyebilir. Bu durum, büyüme sınırsız olduğunda büyük boyutlara yol açabilir.

              This will not only make our Subgraph more efficient, but it will also unlock three features:

              1. Post’u sorgulayarak tüm yorumlarını görebiliriz.

              2. Herhangi bir Comment’te tersine arama yapabilir ve hangi gönderiden geldiğini sorgulayabiliriz.

              3. We can use Derived Field Loaders to unlock the ability to directly access and manipulate data from virtual relationships in our Subgraph mappings.

              Sonuç

              Use the @derivedFrom directive in Subgraphs to effectively manage dynamically growing arrays, enhancing indexing efficiency and data retrieval.

              Büyük dizilerden kaçınma stratejilerinin daha ayrıntılı bir açıklaması için Kevin Jones’un blog yazısına göz atın: Subgraph Geliştiriminde Örnek Uygulamalar: Büyük Dize Kümelerinden Kaçınmak.

              Subgraph Örnek Uygulamalar 1-6

              1. Improve Query Speed with Subgraph Pruning

              2. Improve Indexing and Query Responsiveness by Using @derivedFrom

              3. Improve Indexing and Query Performance by Using Immutable Entities and Bytes as IDs

              4. Improve Indexing Speed by Avoiding eth_calls

              5. Simplify and Optimize with Timeseries and Aggregations

              6. Use Grafting for Quick Hotfix Deployment

              ⁠GitHub'da Düzenle⁠

              Pruning with indexerHintsImmutable Entities and Bytes as IDs
              Bu sayfada
              • Özet
              • @derivedFrom Yönergesi Nasıl Kullanılır
              • @derivedFrom’ın Örnek Kullanımı
              • Sonuç
              • Subgraph Örnek Uygulamalar 1-6
              The GraphStatusTestnetBrand AssetsForumSecurityPrivacy PolicyTerms of Service