Skip to content

Conversation

@sejas
Copy link
Member

@sejas sejas commented May 29, 2025

Related issues

Proposed Changes

  • Simplify and speed up the export logic by removing getBackupContents and getSiteFiles functions.

Testing Instructions

  • Tests should pass
  • Run npm start
  • Go to import/export tab
  • Click on export entire site
  • Observe the produced file contains all the correct files

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@sejas sejas self-assigned this May 29, 2025
@sejas sejas marked this pull request as ready for review June 3, 2025 12:32
@sejas sejas requested review from a team and epeicher June 3, 2025 12:32
Copy link
Contributor

@epeicher epeicher left a comment

Choose a reason for hiding this comment

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

Thanks for simplifying this and reducing the work required in the export process. It works as advertised. I have tested different exports, and I have not found any issues. I have also exported broken symlinks and no errors are returned. LGTM! :shipit:

Copy link
Contributor

Choose a reason for hiding this comment

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

I love it!
CleanShot 2025-06-03 at 16 19 56@2x
😄


( fsPromises.readdir as jest.Mock ).mockResolvedValue( mockFiles );

// Mock fsPromises.stat for canHandle method
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about cleaning up these comments as they seem self-explanatory?

Copy link
Contributor

@katinthehatsite katinthehatsite left a comment

Choose a reason for hiding this comment

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

The functionality looks good and works as expected 👍

From what I understand, the logic that you are removing is now handled by:

	private addWpContent(): void {
		const categories = (
			[ 'uploads', 'plugins', 'themes', 'muPlugins', 'fonts' ] as BackupContentsCategory[]
		 ).filter( ( category ) => this.options.includes[ category ] );
		this.emit( ExportEvents.WP_CONTENT_EXPORT_START );
		for ( const category of categories ) {
			const folderName = category === 'muPlugins' ? 'mu-plugins' : category;
			const absolutePath = path.join( this.options.site.path, 'wp-content', folderName );
			const archivePath = path.relative( this.options.site.path, absolutePath );
			this.archive.directory( absolutePath, archivePath, ( entry ) => {
				const fullArchivePath = path.join( archivePath, entry.name );
				const isExcluded = this.pathsToExclude.some( ( pathToExclude ) =>
					fullArchivePath.startsWith( path.normalize( pathToExclude ) )
				);
				if (
					isExcluded ||
					entry.name.includes( '.git' ) ||
					entry.name.includes( 'node_modules' )
				) {
					return false;
				}
				return entry;
			} );
			this.emit( ExportEvents.WP_CONTENT_EXPORT_PROGRESS, { directory: absolutePath } );
		}
		this.emit( ExportEvents.WP_CONTENT_EXPORT_COMPLETE );
	}

Is that right?

@epeicher
Copy link
Contributor

epeicher commented Jun 4, 2025

The functionality looks good and works as expected 👍

From what I understand, the logic that you are removing is now handled by:

	private addWpContent(): void {
(…)

Is that right?

Great question @katinthehatsite! Let me chime in with an answer. That is absolutely right, before the related changes, this function depended on backupContent.wpcomSites, but after those changes, the backupContent.wpcomSites was not required anymore (and the functions that populated it). We decided to leave the refactor as a follow-up to avoid mixing a refactor with new functionality.

@sejas
Copy link
Member Author

sejas commented Jun 4, 2025

The functionality looks good and works as expected 👍
From what I understand, the logic that you are removing is now handled by:

	private addWpContent(): void {
(…)

Is that right?

Great question @katinthehatsite! Let me chime in with an answer. That is absolutely right, before the related changes, this function depended on backupContent.wpcomSites, but after those changes, the backupContent.wpcomSites was not required anymore (and the functions that populated it). We decided to leave the refactor as a follow-up to avoid mixing a refactor with new functionality.

Yes, reading all the files and saving that list structure was slowly replaced over time. And the last push was when we replaced archive.file with archive.directory on #1448

My assumption is that Antony added the list of files in memory, thinking about future use for it in the progress bar, but that never happened.

@sejas sejas merged commit 186ee42 into trunk Jun 4, 2025
13 checks passed
@sejas sejas deleted the update/STU-536-remove-get-site-files-function-and-speed-up-export branch June 4, 2025 12:02
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.

4 participants