Skip to content

Commit

Permalink
[GraphQL] Leverage objects_version table.
Browse files Browse the repository at this point in the history
## Description

Use the `objects_version` table to speed up point look-ups (via data
loaders) for historical objects (ID + version), and dynamic
fields (object look-up bounding version by parent ID).

With this change, the restriction of accessing dynamic fields only
within the available range is dropped.

## Test plan

```
sui$ cargo nextest run -p sui-graphql-rpc
sui$ cargo nextest run -p sui-graphql-e2e-tests --features pg_integration.
```

Perform a query that involves fetching a large number of dynamic
fields, which should now be fast. The following example, fetching
dynamic fields on a deepbook pool loads 50 dynamic fields in about 5s
from cold (which also requires loading packages for resolution), and
then 2s from there:

```
query {
  owner(
    address: "0x029170bfa0a1677054263424fe4f9960c7cf05d359f6241333994c8830772bdb"
  ) {
    dynamicFields {
      pageInfo {
        hasNextPage
        endCursor
      }
      nodes {
        name {
          type {
            repr
          }
          json
        }
        value {
          ... on MoveValue {
            type {
              repr
            }
            json
          }
          ... on MoveObject {
            contents {
              json
              type {
                repr
              }
            }
          }
        }
      }
    }
  }
}
```
  • Loading branch information
amnn committed May 14, 2024
1 parent fe4808a commit 441c591
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,14 @@ Response: {
"repr": "u64"
}
},
"value": null
"value": {
"contents": {
"json": {
"id": "0x844185d7b145f503838a1d509845a40ee249534f723dd2f003d9efdfc581000d",
"count": "1"
}
}
}
}
}
]
Expand Down Expand Up @@ -892,7 +899,14 @@ Response: {
"repr": "u64"
}
},
"value": null
"value": {
"contents": {
"json": {
"id": "0x844185d7b145f503838a1d509845a40ee249534f723dd2f003d9efdfc581000d",
"count": "1"
}
}
}
}
}
]
Expand Down Expand Up @@ -928,7 +942,17 @@ task 34 'run-graphql'. lines 497-528:
Response: {
"data": {
"parent_version_4": {
"dfAtParentVersion4_outside_range": null
"dfAtParentVersion4_outside_range": {
"name": {
"bcs": "A2RmMQ==",
"type": {
"repr": "0x0000000000000000000000000000000000000000000000000000000000000001::string::String"
}
},
"value": {
"json": "df1"
}
}
},
"parent_version_6": {
"dfAtParentVersion6": null
Expand Down
9 changes: 5 additions & 4 deletions crates/sui-graphql-rpc/src/types/dynamic_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sui_types::dynamic_field::{derive_dynamic_field_id, DynamicFieldInfo, Dynami

use super::available_range::AvailableRange;
use super::cursor::{Page, Target};
use super::object::{self, deserialize_move_struct, Object, ObjectKind, ObjectLookup};
use super::object::{self, deserialize_move_struct, Object, ObjectKind};
use super::type_filter::ExactTypeFilter;
use super::{
base64::Base64, move_object::MoveObject, move_value::MoveValue, sui_address::SuiAddress,
Expand Down Expand Up @@ -174,9 +174,10 @@ impl DynamicField {
let super_ = MoveObject::query(
ctx,
SuiAddress::from(field_id),
ObjectLookup::LatestAt {
parent_version,
checkpoint_viewed_at,
if let Some(parent_version) = parent_version {
Object::under_parent(parent_version, checkpoint_viewed_at)
} else {
Object::latest_at(checkpoint_viewed_at)
},
)
.await?;
Expand Down
Loading

0 comments on commit 441c591

Please sign in to comment.