diff --git a/packages/fuel-indexer-lib/src/defaults.rs b/packages/fuel-indexer-lib/src/defaults.rs index c89df3c45..599fc3e6a 100644 --- a/packages/fuel-indexer-lib/src/defaults.rs +++ b/packages/fuel-indexer-lib/src/defaults.rs @@ -143,6 +143,3 @@ pub const DISABLE_TOOLCHAIN_VERSION_CHECK: bool = false; /// Default Fuel network to use. pub const NETWORK: &str = "beta-4"; - -/// Default limit for the number of `find_many` results. -pub const FIND_MANY_LIMIT: usize = 255; diff --git a/packages/fuel-indexer-plugin/src/wasm.rs b/packages/fuel-indexer-plugin/src/wasm.rs index 1b8568b47..0c6977725 100644 --- a/packages/fuel-indexer-plugin/src/wasm.rs +++ b/packages/fuel-indexer-plugin/src/wasm.rs @@ -21,7 +21,7 @@ pub use crate::find::{Field, Filter, OptionField, ToFilter}; // These are instantiated with functions which return // `Result`. `wasmer` unwraps the `Result` and uses the -// `Err` variant for ealy exit. +// `Err` variant for early exit. extern "C" { fn ff_get_object(type_id: i64, ptr: *const u8, len: *mut u8) -> *mut u8; fn ff_find_many(type_id: i64, limit: u64, ptr: *const u8, len: *mut u8) -> *mut u8; @@ -69,7 +69,7 @@ pub trait Entity<'a>: Sized + PartialEq + Eq + std::fmt::Debug { /// Convert database row representation into an instance of an entity. fn from_row(vec: Vec) -> Self; - /// Convert an instance of an entity into row representation for use in a database. + /// Convert an instance of an entity into a row representation for use in a database. fn to_row(&self) -> Vec; /// Returns an entity's internal type ID. @@ -129,12 +129,12 @@ pub trait Entity<'a>: Sized + PartialEq + Eq + std::fmt::Debug { /// Finds the first entity that satisfies the given constraints. fn find(query: impl ToFilter) -> Option { - let result = Self::find_many(query, Some(1)); + let result = Self::find_many(1, query); result.into_iter().next() } /// Finds the entities that satisfy the given constraints. - fn find_many(query: impl ToFilter, limit: Option) -> Vec { + fn find_many(limit: usize, query: impl ToFilter) -> Vec { unsafe { let buff = bincode::serialize(&query.to_filter()) .expect("Failed to serialize query"); @@ -142,7 +142,7 @@ pub trait Entity<'a>: Sized + PartialEq + Eq + std::fmt::Debug { let ptr = ff_find_many( Self::TYPE_ID, - limit.unwrap_or(fuel_indexer_lib::defaults::FIND_MANY_LIMIT) as u64, + limit as u64, buff.as_ptr(), bufflen.as_mut_ptr(), ); diff --git a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs index 274be6e1a..108d54ed8 100644 --- a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs +++ b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs @@ -649,11 +649,11 @@ mod fuel_indexer_test { // Test searching for multiple entities let fs: Vec = FindEntity::find_many( + 10, FindEntity::string_value() .gt("f".to_string()) .order_by(FindEntity::value()) .asc(), - None, ); assert_eq!(fs.len(), 4); assert_eq!(fs[0].string_value, "find2"); @@ -662,11 +662,11 @@ mod fuel_indexer_test { assert_eq!(fs[3].string_value, "find5"); let fs: Vec = FindEntity::find_many( + 10, FindEntity::string_value() .gt("f".to_string()) .order_by(FindEntity::value()) .desc(), - None, ); assert_eq!(fs.len(), 4); @@ -677,11 +677,11 @@ mod fuel_indexer_test { // Test searching for multiple entities with a result limit let fs: Vec = FindEntity::find_many( + 2, FindEntity::string_value() .gt("f".to_string()) .order_by(FindEntity::value()) .desc(), - Some(2), ); assert_eq!(fs.len(), 2);