Add FICTIONEER_STORY_CARD_CHAPTER_LIMIT constant

This commit is contained in:
Tetrakern 2024-08-15 01:51:45 +02:00
parent 45ddf81c5a
commit 8e709d18f8
3 changed files with 13 additions and 2 deletions

View File

@ -1599,6 +1599,7 @@ define( 'CONSTANT_NAME', value );
| FICTIONEER_PARTIAL_CACHE_EXPIRATION_TIME | integer | Time until a cached partial expires in seconds. Default `4 * HOUR_IN_SECONDS`.
| FICTIONEER_CARD_CACHE_LIMIT | integer | Number of cards cached by the story card cache feature if enabled. Default `50`.
| FICTIONEER_CARD_CACHE_EXPIRATION_TIME | integer | Time until the whole story card cache expires in seconds. Default `HOUR_IN_SECONDS`.
| FICTIONEER_STORY_CARD_CHAPTER_LIMIT | integer | Maximum number of chapters shown on story cards. Default 3.
| FICTIONEER_CACHE_PURGE_ASSIST | boolean | Whether to call the cache purge assist function on post updates. Default `true`.
| FICTIONEER_RELATIONSHIP_PURGE_ASSIST | boolean | Whether to purge related post caches. Default `true`.
| FICTIONEER_CHAPTER_LIST_TRANSIENTS | boolean | Whether to cache chapter lists on story pages as Transients. Default `true`.

View File

@ -298,6 +298,11 @@ if ( ! defined( 'FICTIONEER_CARD_CACHE_EXPIRATION_TIME' ) ) {
define( 'FICTIONEER_CARD_CACHE_EXPIRATION_TIME', HOUR_IN_SECONDS );
}
// Integer: Maximum number of chapters shown on story cards
if ( ! defined( 'FICTIONEER_STORY_CARD_CHAPTER_LIMIT' ) ) {
define( 'FICTIONEER_STORY_CARD_CHAPTER_LIMIT', 3 );
}
/*
* Booleans
*/

View File

@ -36,7 +36,12 @@ $post_id = $post->ID;
$story = fictioneer_get_story_data( $post_id );
$story_link = ( $story['redirect'] ?? 0 ) ?: get_permalink( $post_id );
$latest = $args['show_latest'] ?? FICTIONEER_SHOW_LATEST_CHAPTERS_ON_STORY_CARDS;
$chapter_ids = array_slice( $story['chapter_ids'], $latest ? -3 : 0, 3, true ); // Does not include hidden or non-chapters
$chapter_limit = max( 0, FICTIONEER_STORY_CARD_CHAPTER_LIMIT );
$chapter_ids = array_slice(
$story['chapter_ids'],
$latest ? -1 * $chapter_limit : 0, $chapter_limit,
true
); // Does not include hidden or non-chapters
$chapter_count = count( $chapter_ids );
$excerpt = fictioneer_first_paragraph_as_excerpt(
fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id )
@ -160,7 +165,7 @@ if ( $card_cache_active ) {
'post_status' => 'publish',
'post__in' => $chapter_ids ?: [0], // Must not be empty!
'orderby' => 'post__in',
'posts_per_page' => -1,
'posts_per_page' => FICTIONEER_STORY_CARD_CHAPTER_LIMIT,
'no_found_rows' => true, // Improve performance
'update_post_term_cache' => false // Improve performance
);