Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only update SQLite plugin if the version was updated in Studio
  • Loading branch information
bgrgicak committed Mar 3, 2025
commit e14f49db7ca825a3a8c8a17cafac0f3e3605ef66
2 changes: 1 addition & 1 deletion src/lib/sqlite-database-integration-release.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const SQLITE_DATABASE_INTEGRATION_VERSION = 'v2.1.17-alpha';
export const SQLITE_DATABASE_INTEGRATION_VERSION = 'v2.1.17-alpha';

export const SQLITE_DATABASE_INTEGRATION_RELEASE_URL = `https://github.com/Automattic/sqlite-database-integration/archive/refs/tags/${ SQLITE_DATABASE_INTEGRATION_VERSION }.zip`;
28 changes: 3 additions & 25 deletions src/lib/sqlite-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getServerFilesPath } from 'src/storage/paths';
import { SQLITE_FILENAME, SQLITE_FILENAME_LEGACY } from 'vendor/wp-now/src/constants';
import { downloadSqliteIntegrationPlugin } from 'vendor/wp-now/src/download';
import getSqlitePath from 'vendor/wp-now/src/get-sqlite-path';
import { SQLITE_DATABASE_INTEGRATION_VERSION } from './sqlite-database-integration-release';

export async function isSqlLiteInstalled( installPath: string ) {
// Check both standard and legacy (-main) paths
Expand Down Expand Up @@ -39,7 +40,7 @@ async function isNewSqliteVersionAvailable() {
const installedVersion = semver.coerce(
await getSqliteVersionFromInstallation( getSqlitePath() )
);
const latestVersion = semver.coerce( await getLatestSqliteVersion() );
const latestVersion = semver.coerce( SQLITE_DATABASE_INTEGRATION_VERSION );
if ( ! installedVersion ) {
return true;
}
Expand All @@ -58,9 +59,7 @@ async function isNewSqliteVersionAvailable() {
* @returns True if the SQLite integration is outdated.
*/
export async function isSqliteInstallationOutdated( sitePath: string ): Promise< boolean > {
const serverFilesVersion = semver.coerce(
await getSqliteVersionFromInstallation( getSqlitePath() )
);
const serverFilesVersion = semver.coerce( SQLITE_DATABASE_INTEGRATION_VERSION );
const siteVersion = semver.coerce( await getSqliteVersionFromInstallation( sitePath ) );

if ( ! siteVersion ) {
Expand All @@ -87,27 +86,6 @@ export async function getSqliteVersionFromInstallation(
return matches?.[ 1 ] || '';
}

let latestSqliteVersionsCache: string | null = null;

async function getLatestSqliteVersion() {
// Only fetch the latest version once per app session
if ( latestSqliteVersionsCache ) {
return latestSqliteVersionsCache;
}

try {
const response = await fetch(
'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=sqlite-database-integration'
);
const data: Record< string, string > = await response.json();
latestSqliteVersionsCache = data.version;
} catch ( _error ) {
// Discard the failed fetch, return the cache
}

return latestSqliteVersionsCache;
}

/**
* Removes legacy `sqlite-integration-plugin` installations from the specified
* installation path that including a `-main` branch suffix.
Expand Down