families_missing_metrics( self::BATCH ); if ( empty( $families ) ) { return; } // Short lock so concurrent admin loads don't pile on Google requests. set_transient( 'easyfonts_metrics_lock', 1, self::THROTTLE ); $downloader = new Downloader(); $reader = new FontMetricsReader(); $registry = new Registry(); foreach ( $families as $family ) { $bytes = $downloader->fetch_family_ttf( $family['family'], (string) $family['weight'] ); if ( ! $bytes ) { continue; } $metrics = $reader->read( $bytes ); if ( $metrics ) { $registry->set_family_metrics( $family['family'], $metrics ); } } } /** * Find Google families with no metrics yet. * * @param int $limit Max families. * @return array */ private function families_missing_metrics( int $limit ): array { global $wpdb; $table = $wpdb->prefix . 'easyfonts_fonts'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery $rows = $wpdb->get_results( $wpdb->prepare( "SELECT family, MIN(weight) AS weight FROM {$table} WHERE provider = 'google' AND ( metrics IS NULL OR metrics = '' ) GROUP BY family LIMIT %d", $limit ), ARRAY_A ); return $rows ? $rows : array(); } }