waku-org / nwaku

Waku node and protocol.
Other
183 stars 46 forks source link

chore(storev3): only select the `messageHash` column when using a store query with `include_data: false` #2637

Open richard-ramos opened 3 weeks ago

richard-ramos commented 3 weeks ago

Consider modifying the getMessages function in line 139 of https://github.com/waku-org/nwaku/blob/4e57308905158cff62f2616732867121c92b524f/waku/waku_archive/archive.nim to also pass the includeData value, and then, in the drivers define a query that will only do a SELECT messageHash FROM messages ....... if the value from includeData is true.

We should check the query plan from sqlite/postgres, of course, but depending on how the indices were defined, this should be more efficient, due to reduced disk i/o and data transfer from disk to memory, since the query will be satisfied by only reading the values from the index, without needing to fetch additional data from the table. I imagine this would be the case as the following indices are defined in the code as far as i could see all the columns match the attributes that can be used as criteria in the store query requests:

Primary Key: `messageHash`
Index: `contentTopic`, `pubsubTopic`, `senderTimestamp`, `id`
Index: `storedAt`