Open toolstack opened 9 months ago
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.
Thank you!
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?
@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.
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 ) );
Use user/post meta to store favourited statuses.