Analogy: You can either buy all the potatoes and then decide what potatoes to use for making 🍟 or you can filter out the good potatoes while purchasing them. In either case the fries will be made of good 🥔 #Day7#Solana#filtering
Sorry 😛, stay with me. Here purchasing 🥔 refer to fetching accounts data using 2 approaches:
1. Fetching all acc. without any data (just their pubKeys) ~ (purchasing all)
2. Filtering what acc. to fetch, before fetching them without any data ~ (filtering before buying)
In the 1st approach, one is fetching accounts without any data.
Now what that means is, we have a pubkey with us.
Whenever a client demands for data, we will be using the pubkey we saved earlier to further fetch associated account data.
In the 2nd approach instead of fetching pubkeys of all the accounts associated with my program, I will be fetching only those accounts which contains the data I am interested in.
Why do both these approaches matters? Say, you build a phone directory. It has millions of records. Any user won't be interested in seeing million records at a single place. So why fetch them all together?
Important concepts I learnt today,
Paging - to split my records into different pages
use of dataSlice and filters inside of getProgramAccounts() function call in order to slice my incoming data buffer and then apply filtering criteria over it.
Will implement the newly learnt concepts in my 'StudentPROject' later. calling it a day. In the past few days, I have learnt so much yet so little. This journey is going to be beautiful 😌🤌
Please don't like my tweet below. Please don't let others see my potato analogy below. Please stop eating fries.. You won't listen to me? Prove it by doing reverse to what I said :)
The curious case of using offset values with data slice property 🤔 #Solana#Day8#offset
dataSlice is used to literally slice 🔪 the returned data buffer.
Let's say you have a dataBuffer in which the first 8bytes are storing data you don't need. So, we can slice that from all the data and then carry out operations on the remaining data. Optimized much? 🤌
Now, the no. of bytes, to slice from the beginning, is defined as an 'offset' value inside of it.
Or
using offset value in dataSlice defines how much bytes to slice, in the returned buffer.