Conversation
leohhhn
left a comment
There was a problem hiding this comment.
Nice start! I'm leaving comments on how you can improve your code below. Please check them out
- Convert Register, Upvote, Downvote, and AddComment URLs to txlink.Call() - Use builder pattern for AddComment to allow user-editable text field - Cache match count to reduce redundant len() calls
Thank you for all your comments. I have corrected and tested everything. Let me know if you have anything else to add ! |
leohhhn
left a comment
There was a problem hiding this comment.
leaving some comments, check them out
| // ============================================================================= | ||
|
|
||
| // FilterUsers returns paginated and filtered user results | ||
| func FilterUsers(searchTerm string, limit int, offset int) ([]address, int) { |
There was a problem hiding this comment.
check if you can use p/nt/avl/pager for paging in this case instead of writing your own pager
There was a problem hiding this comment.
I can't, because I'm currently using an array and not a tree. If I switch to a tree, I think it will unnecessarily complicate the code.
There was a problem hiding this comment.
It's not only about paging. In Gno, every global variable is persisted to storage after each transaction. If you maintain a sorted slice, any update requires reallocating and rewriting the entire slice to storage. With 100k users, that's 100k storage writes per update.
Instead, use an AVL tree keyed by score. AVL trees maintain lexicographic order automatically.
See gno.land/r/leon/hor for a pattern using padded score keys for numeric sorting.
| // ============================================================================= | ||
|
|
||
| // FilterUsers returns paginated and filtered user results | ||
| func FilterUsers(searchTerm string, limit int, offset int) ([]address, int) { |
There was a problem hiding this comment.
It's not only about paging. In Gno, every global variable is persisted to storage after each transaction. If you maintain a sorted slice, any update requires reallocating and rewriting the entire slice to storage. With 100k users, that's 100k storage writes per update.
Instead, use an AVL tree keyed by score. AVL trees maintain lexicographic order automatically.
See gno.land/r/leon/hor for a pattern using padded score keys for numeric sorting.
TrustFactor is a realm where you can upvote or downvote a user to give them a score out of 10. This score can be used by a platform to restrict users with a trust score below a certain threshold. In this system, I also added an SVG widget that can be imported to a user's homepage, for example, to display their trust score.