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

3.18 - Data collection related to disk usage #7181

Open
piotrbak opened this issue Dec 12, 2024 · 5 comments · May be fixed by #7199
Open

3.18 - Data collection related to disk usage #7181

piotrbak opened this issue Dec 12, 2024 · 5 comments · May be fixed by #7199
Assignees
Labels
effort: [S] 1-2 days of estimated development time type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Milestone

Comments

@piotrbak
Copy link
Contributor

User Story
As a product team, we want to know the number of fonts and their size on each website that allows data collection

Acceptance Criteria
Only for websites that allowed data collection

  • We should calculate the number of fonts that are present in the /wp-content/cache/fonts/1/google-fonts/fonts/ directory
  • We should calculate total size of all fonts that are present in the /wp-content/cache/fonts/1/google-fonts/fonts/ directory
  • The above data should be send to mixpanel
  • We could use a cron to calculate this and keep this data in transient for one week to avoid unnecesary processing
@piotrbak piotrbak added the type: enhancement Improvements that slightly enhance existing functionality and are fast to implement label Dec 12, 2024
@piotrbak piotrbak added this to the 3.18 milestone Dec 12, 2024
@Khadreal
Copy link
Contributor

Khadreal commented Dec 16, 2024

Scope a solution ✅

In the subscriber class we can addadmin_init hook and a callback , we would then set the event in the callback

if ( ! as_has_scheduled_action( 'media_fonts_data_collection' ) ) {
	as_schedule_recurring_action( strtotime("+1 week"), 300, 'media_fonts_data_collection' );
}

In subscriber class, we should add this to the get_subcribed_events
'media_fonts_data_collection' => 'process_media_font_data_collection'

Add process_media_font_data_collection method to the Subscriber class

public function process_media_font_data_collection() {
	$media_font_data = get_transient( 'rocket_media_fonts_data' );
	//If data has been populated, bail out early.
	if(false !== $media_font_data) {
		return;
	}

	$fonts = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $this->base_path ) );
	$allowed_extensions [
		'woff',
		'woff2',
		'ttf',
		'otf'
	];
	$total_font_count = 0;
	$total_font_size = 0;
	foreach($fonts as $file){
		//check file is not a directory.
		if( is_dir( $file )  ) {
			continue;
		}

		$extension = strtolower( pathinfo( $file->getFilename(), PATHINFO_EXTENSION ) );

		if ( in_array( $extension, $allowed_extensions, true ) ) {
            $total_font_count++;
            $total_font_size += $file->getSize();
        }

	}

	set_transiet( 'rocket_media_fonts_data', [
		'Total number of fonts' => $total_font_count,
		'Total number of font file size' => $total_font_size
	]);
}

Finally we will update the admin file

$media_font_data = get_transient( 'rocket_media_fonts_data' );
if ( false !== $media_font_data ) {
  $data['media_font_data'] = $media_font_data;
}

Lastly, update the scheduled events array here when the plugin is uninstall

Estimation:

[S]

@Khadreal Khadreal added the effort: [S] 1-2 days of estimated development time label Dec 16, 2024
@wordpressfan
Copy link
Contributor

Thanks @Khadreal

I have some concerns, sharing it here to discuss:

  1. wp_schedule_single_event is used to schedule only one time event but I believe u need a recurring one, correct? we can think of using action scheduler function as_schedule_recurring_action, WDYT?
  2. The mentioned line will be triggered with each page visit (for pages with google fonts) so triggering the code here is too much.
  3. Why do u want to trigger it one week after?

@Khadreal
Copy link
Contributor

@wordpressfan
1 -- I'm working with the assumption that this will be trigger once, if it would be more than that, I'll modify the grooming
3 -- the AC said this "We could use a cron to calculate this and keep this data in transient for one week to avoid unnecesary processing"

@remyperona
Copy link
Contributor

I agree we can use an AS recurring action to handle that

@wordpressfan
Copy link
Contributor

Awesome, I believe this should work.

@remyperona remyperona self-assigned this Dec 19, 2024
@remyperona remyperona linked a pull request Dec 19, 2024 that will close this issue
8 tasks
@remyperona remyperona linked a pull request Dec 19, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: [S] 1-2 days of estimated development time type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants