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

Add storage of favourited statuses #63

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

toolstack
Copy link
Contributor

Use user/post meta to store favourited statuses.

@toolstack toolstack force-pushed the save-favourites branch 3 times, most recently from 09038e7 to c451222 Compare January 9, 2024 23:38
Copy link
Owner

@akirk akirk left a comment

Choose a reason for hiding this comment

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

I can see how this makes sense as a small scale implementation but I do think we should go the extra mile and implement it with a taxonomy.
If Friends plugin is installed, it already stores reactions as terms and getting the favourite count should be done by querying the taxonomy.
I'd also like to use this approach versus storing serialized post ids (what if you delete posts, etc.).
I could see that we add filters so that as a quick win you could get this small scale implementation that works for you by using another plugin or a code snippet.

@akirk akirk mentioned this pull request Jan 10, 2024
@toolstack
Copy link
Contributor Author

Makes sense, deleting a post isn't a big deal as it just won't be returned during the favourites list generation, but it does hang around in the array, so yeah, not the best.

I'll add some filters to it and push an update tomorrow.

@akirk
Copy link
Owner

akirk commented Jan 10, 2024

Thank you!

@toolstack
Copy link
Contributor Author

I've been thinking about this a bit more and took a look at how Friends does the reactions, Friends uses a non-hierarchical taxonomy to do the storage, so you're creating one taxa for each user/action.

I'm not an expert on taxa, but would it be possible instead to use a hierarchical taxa so that it could be something like:

enable-mastodon-apps->user_id->favourite

And then for bookmarks:

enable-mastodon-apps->user_id->bookmark

The other question I had was around the following of hashtags... I don't think you can have a taxa of a taxa right? Aka you can't add a enable-mastodon-apps->user_id->hashtag taxa to a categories or tags taxa?

@toolstack toolstack marked this pull request as draft January 15, 2024 20:02
@toolstack toolstack force-pushed the save-favourites branch 4 times, most recently from 101b91a to 403f699 Compare January 15, 2024 21:43
@toolstack toolstack marked this pull request as ready for review January 15, 2024 21:44
@toolstack
Copy link
Contributor Author

@akirk I've converted to terms for this PR, however I've left the favourite count as a post_meta, as there seems to be no easy way to count terms over multiple taxonomies (aka no wildcards allowed in taxonomy terms in tax_queries).

That only leaves two options, creating one tax_subquery for each user (not a very nice/scaleable solution), or a custom SQL query.

Neither are pleasant and for a simple count, the post_meta is probably lighter and more scaleable anyway.

@toolstack
Copy link
Contributor Author

Just for reference, here's the SQL required to do the count:

$raw_sql = "SELECT count(*) FROM {$wpdb->term_taxonomy} INNER JOIN {$wpdb->term_relationships} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id WHERE {$wpdb->term_taxonomy}.taxonomy LIKE %s AND {$wpdb->term_relationships}.object_id = %d;";

$sql = $wpdb->prepare( $raw_sql, SELF::FAVOURITES_TAXONOMY_PREFIX . '%', intval( $post_id ) );

return intval( $wpdb->get_var( $sql ) );

@toolstack toolstack force-pushed the save-favourites branch 2 times, most recently from 79a8dc3 to c855fc2 Compare January 16, 2024 02:10
Store and retrieve favourite statuses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants