I have very simple table items
with the following structure:
struct [[eosio::table]] item
{
uint64_t id;
uint64_t state;
string description;
uint64_t primary_key() const { return id; }
uint64_t by_state() const { return state; }
};
typedef eosio::multi_index<"items"_n, item,
eosio::indexed_by<"bystate"_n, eosio::const_mem_fun<item, uint64_t, &item::by_state>>> items;
items items_table;
and I have an action within smart contract, where I need to filter the items by particular state and loop the result executing a simple processing for each of the filtered items. Currently I am using the following implementation (simply looping the whole table, searching for the items on specified state):
for (auto iter = items_table.begin(); iter != items_table.end(); iter++)
{
if (iter->state == state)
{
// handle item record
...
}
}
but it is not sufficient if table contains enormous amount of items.
Does anyone knows is there a way (is EOS) to fetch the item records on specified state using secondary index "bystate" and further loop those records and apply another logic for each of them ?