Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(blog): store posts in slices & include chronological sorting #1367

Closed
wants to merge 9 commits into from

Conversation

leohhhn
Copy link
Contributor

@leohhhn leohhhn commented Nov 13, 2023

Description

This PR implements a modification in the storage mechanism for blog posts within the p/demo/blog package. Previously, an AVL tree was used for storing posts, leading to an inconsistent order during retrieval.

Now, the PR updates the Blog struct to incorporate a postSlice struct, replacing the AVL tree. This change ensures that blog posts are maintained in the order how they were added, providing a consistent and predictable order.

Also, as per @thehowl's suggestion, the postSlice struct implements the sort.Sort interface, allowing for sorting by date of creation down the line when needed.

cc @thehowl @moul

Fixes gnolang/blog#20, fixes #1285.

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Nov 13, 2023
Copy link

codecov bot commented Nov 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (aaeb808) 55.91% compared to head (22305c3) 55.91%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1367   +/-   ##
=======================================
  Coverage   55.91%   55.91%           
=======================================
  Files         421      421           
  Lines       65444    65444           
=======================================
  Hits        36595    36595           
  Misses      25991    25991           
  Partials     2858     2858           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

examples/gno.land/p/demo/blog/blog.gno Outdated Show resolved Hide resolved
examples/gno.land/p/demo/blog/util.gno Outdated Show resolved Hide resolved
@thehowl thehowl linked an issue Nov 13, 2023 that may be closed by this pull request
@leohhhn
Copy link
Contributor Author

leohhhn commented Nov 14, 2023

@thehowl will do a more detailed refactor once I'm back from Devconnect - or, @waymobetta, if you've the time to jump on this you can.

@leohhhn leohhhn changed the title feat: sort blog posts chronologically feat(blog): store posts in slices & include chronological sorting Nov 22, 2023
@leohhhn
Copy link
Contributor Author

leohhhn commented Nov 22, 2023

Hey @thehowl, I refactored with the suggestions that you guys made. I did some small reorgs of the package as well.

Since the Post struct also has a Comments AVL tree, I am considering doing the same refactor to slices for comments as well. What do you think about it?

@leohhhn leohhhn marked this pull request as ready for review November 22, 2023 13:17
@leohhhn leohhhn requested a review from a team as a code owner November 22, 2023 13:17
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM

examples/gno.land/p/demo/blog/types.gno Show resolved Hide resolved
examples/gno.land/p/demo/blog/util.gno Show resolved Hide resolved
examples/gno.land/p/demo/blog/util.gno Outdated Show resolved Hide resolved
examples/gno.land/p/demo/blog/blog.gno Outdated Show resolved Hide resolved
examples/gno.land/p/demo/blog/blog.gno Outdated Show resolved Hide resolved
@thehowl
Copy link
Member

thehowl commented Nov 24, 2023

Since the Post struct also has a Comments AVL tree, I am considering doing the same refactor to slices for comments as well. What do you think about it?

sounds good to me.

Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just reviewed again, this LGTM, but I would still remove types.go and move its types back into the respective files

Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 💯

EDIT:

@leohhhn Please check the CI, the tests are failing

Comment on lines +4 to +6
"gno.land/p/demo/seqid"
"std"
"time"
Copy link
Member

@moul moul Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we configure our linter to flag import style issues?

cc @gnolang/tech-staff

Comment string
}

type postSlice []*Post
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use seqid with an avl.Tree instead of a slice? I believe it allows for an always growing key string, which would help keep the avl.Tree ordered. cc @thehowl

Comment on lines +13 to +14
for _, post := range p {
if post.Slug == slug {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of an AVL tree is to optimize the lazy loading of necessary data and skip unnecessary posts. Unlike this implementation, an AVL tree is scalable and will efficiently handle larger data sets.

@leohhhn
Copy link
Contributor Author

leohhhn commented Jan 9, 2024

Closing this PR to start on a clean slate because of the feedback I've received. Will implement this change with seqID / AVLs.

New PR: #1541

@leohhhn leohhhn closed this Jan 9, 2024
@leohhhn leohhhn deleted the feat/blog-sort branch January 11, 2024 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Archived in project
Development

Successfully merging this pull request may close these issues.

make r/demo/blog chronological feat: sort articles
4 participants