-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1578 from appwrite/perf-improvements
Perf improvements
- Loading branch information
Showing
1,112 changed files
with
163 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,8 @@ | |
"test": "npm run test:integration && npm run test:unit", | ||
"test:integration": "playwright test", | ||
"test:unit": "vitest", | ||
"optimize": "node ./scripts/optimize-assets.js" | ||
"optimize": "node ./scripts/optimize-assets.js", | ||
"optimize:all": "node ./scripts/optimize-all.js" | ||
}, | ||
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a", | ||
"dependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { readdirSync, statSync } from 'fs'; | ||
import { join, relative, resolve } from 'path'; | ||
import sharp from 'sharp'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const __dirname = fileURLToPath(new URL('.', import.meta.url)); | ||
const project_root = resolve(__dirname, '..'); | ||
|
||
// Directories to search in | ||
const search_dirs = ['src', 'static', 'routes', 'lib']; | ||
|
||
// Directories to skip | ||
const excluded_dirs = ['node_modules', '.svelte-kit', 'build', '.git', 'assets/']; | ||
|
||
/** | ||
* @type {{ | ||
* jpeg: sharp.JpegOptions, | ||
* webp: sharp.WebpOptions, | ||
* png: sharp.PngOptions, | ||
* gif: sharp.GifOptions, | ||
* avif: sharp.AvifOptions | ||
* }} | ||
*/ | ||
const config = { | ||
jpeg: { | ||
quality: 100 | ||
}, | ||
webp: { | ||
lossless: true | ||
}, | ||
png: { | ||
quality: 100 | ||
}, | ||
gif: { | ||
quality: 100 | ||
}, | ||
avif: { | ||
lossless: true | ||
} | ||
}; | ||
|
||
/** @type {sharp.ResizeOptions} */ | ||
const resize_config = { | ||
width: 1280, | ||
height: 1280, | ||
fit: sharp.fit.inside, | ||
withoutEnlargement: true | ||
}; | ||
|
||
function* walk_directory(dir) { | ||
try { | ||
const files = readdirSync(dir); | ||
|
||
for (const file of files) { | ||
const pathToFile = join(dir, file); | ||
const relativePath = relative(project_root, pathToFile); | ||
|
||
// Skip excluded directories | ||
if (excluded_dirs.some((excluded) => relativePath.includes(excluded))) { | ||
continue; | ||
} | ||
|
||
const isDirectory = statSync(pathToFile).isDirectory(); | ||
if (isDirectory) { | ||
yield* walk_directory(pathToFile); | ||
} else { | ||
yield pathToFile; | ||
} | ||
} | ||
} catch (error) { | ||
console.error(`Error accessing directory ${dir}:`, error.message); | ||
} | ||
} | ||
|
||
function is_image(file) { | ||
const extension = file.split('.').pop()?.toLowerCase(); | ||
return extension && Object.keys(config).includes(extension); | ||
} | ||
|
||
function format_size(bytes) { | ||
const sizes = ['B', 'KB', 'MB']; | ||
const i = Math.floor(Math.log(bytes) / Math.log(1024)); | ||
return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`; | ||
} | ||
|
||
async function optimize_image(file) { | ||
const is_animated = file.endsWith('.gif'); | ||
const image = sharp(file, { animated: is_animated }); | ||
|
||
try { | ||
const size_before = (await image.toBuffer()).length; | ||
const meta = await image.metadata(); | ||
|
||
if (!meta.format || !config[meta.format]) { | ||
console.warn(`Unsupported format for file: ${file}`); | ||
return; | ||
} | ||
|
||
const buffer = await image[meta.format](config[meta.format]) | ||
.resize(resize_config) | ||
.toBuffer(); | ||
const size_after = buffer.length; | ||
|
||
if (size_after >= size_before) { | ||
console.log(`Skipping ${relative(project_root, file)} - no size reduction possible`); | ||
return; | ||
} | ||
|
||
const savings = (((size_before - size_after) / size_before) * 100).toFixed(2); | ||
console.log(`Optimizing ${relative(project_root, file)}`); | ||
console.log(` Before: ${format_size(size_before)}`); | ||
console.log(` After: ${format_size(size_after)}`); | ||
console.log(` Saved: ${savings}%`); | ||
|
||
await sharp(buffer).toFile(file); | ||
} catch (error) { | ||
console.error(`Error processing ${file}:`, error.message); | ||
} | ||
} | ||
|
||
async function main() { | ||
let total_files = 0; | ||
let processed_files = 0; | ||
|
||
console.log('Starting image optimization...\n'); | ||
|
||
for (const search_dir of search_dirs) { | ||
const full_path = join(project_root, search_dir); | ||
|
||
try { | ||
if (!statSync(full_path).isDirectory()) continue; | ||
|
||
for (const file of walk_directory(full_path)) { | ||
if (!is_image(file)) continue; | ||
total_files++; | ||
|
||
await optimize_image(file); | ||
processed_files++; | ||
} | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
console.log(`Directory ${search_dir} not found - skipping`); | ||
} else { | ||
console.error(`Error processing ${search_dir}:`, error.message); | ||
} | ||
} | ||
} | ||
|
||
console.log(`\nOptimization complete!`); | ||
console.log(`Processed ${processed_files} of ${total_files} image files`); | ||
} | ||
|
||
await main(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Binary file not shown.
Diff not rendered.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-197 KB
(73%)
static/images/blog/10-git-commands-you-should-start-using/cover.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-8 Bytes
(100%)
static/images/blog/Behind_the_pull_request_Stories_from_contributors.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-79 Bytes
(100%)
static/images/blog/a-recap-of-init/thumbnails/thumbnail-1.png
Oops, something went wrong.
Binary file modified
BIN
-233 Bytes
(100%)
static/images/blog/a-recap-of-init/thumbnails/thumbnail-2fa.png
Oops, something went wrong.
Binary file modified
BIN
-221 Bytes
(100%)
static/images/blog/a-recap-of-init/thumbnails/thumbnail-db.png
Oops, something went wrong.
Binary file modified
BIN
-1.3 KB
(100%)
static/images/blog/a-recap-of-init/thumbnails/thumbnail-init-shorts.png
Oops, something went wrong.
Binary file modified
BIN
-284 Bytes
(100%)
static/images/blog/a-recap-of-init/thumbnails/thumbnail-messaging.png
Oops, something went wrong.
Binary file modified
BIN
-155 Bytes
(100%)
static/images/blog/a-recap-of-init/thumbnails/thumbnail-ssr.png
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-1003 Bytes
(99%)
static/images/blog/add-a-search-function-to-your-app/connect.png
Oops, something went wrong.
Binary file modified
BIN
-4.97 KB
(94%)
static/images/blog/add-a-search-function-to-your-app/connecttemplate.png
Oops, something went wrong.
Binary file modified
BIN
-867 Bytes
(100%)
static/images/blog/add-a-search-function-to-your-app/cover.png
Oops, something went wrong.
Binary file modified
BIN
-6.25 KB
(90%)
static/images/blog/add-a-search-function-to-your-app/functions.png
Oops, something went wrong.
Binary file modified
BIN
-2.2 KB
(99%)
static/images/blog/add-a-search-function-to-your-app/templates.png
Oops, something went wrong.
Binary file modified
BIN
-6.52 KB
(92%)
static/images/blog/add-a-search-function-to-your-app/variables.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-36 Bytes
(100%)
static/images/blog/announcing-appwrite-daily-dot-dev-squad/daily.dev-squad.png
Oops, something went wrong.
Binary file modified
BIN
+53 Bytes
(100%)
static/images/blog/announcing-appwrite-is-gdpr-compliant/GDPR-Announcement.png
Oops, something went wrong.
Binary file modified
BIN
-8.74 KB
(93%)
static/images/blog/announcing-appwrite-is-gdpr-compliant/dpa-card.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-1.73 KB
(100%)
static/images/blog/announcing-init-faster-smoother-better/init-cover.png
Oops, something went wrong.
Binary file modified
BIN
-9 Bytes
(100%)
static/images/blog/announcing-init-faster-smoother-better/init-swag.png
Oops, something went wrong.
Binary file modified
BIN
-37 Bytes
(100%)
static/images/blog/announcing-init-faster-smoother-better/init-ticket.png
Oops, something went wrong.
Binary file modified
BIN
-217 Bytes
(100%)
static/images/blog/appwrite-1.5-now-available-on-cloud/cloud15.png
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
+25 Bytes
(100%)
static/images/blog/appwrite-competitor-comparison/cover.png
Oops, something went wrong.
Binary file modified
BIN
+0 Bytes
(100%)
static/images/blog/appwrite-decoded-bradley/bradley-cover.png
Oops, something went wrong.
Binary file modified
BIN
-129 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-career-update.png
Oops, something went wrong.
Binary file modified
BIN
-43 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-conference.png
Oops, something went wrong.
Binary file modified
BIN
-16 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-cover.png
Oops, something went wrong.
Binary file modified
BIN
+30 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-github-universe.png
Oops, something went wrong.
Binary file modified
BIN
-4 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-nextjs.png
Oops, something went wrong.
Binary file modified
BIN
-11 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-post-devrel.png
Oops, something went wrong.
Binary file modified
BIN
-2.55 KB
(99%)
static/images/blog/appwrite-decoded-dennis/dennis-post-github.png
Oops, something went wrong.
Binary file modified
BIN
-45 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-post-team.png
Oops, something went wrong.
Binary file modified
BIN
-124 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-remote.png
Oops, something went wrong.
Binary file modified
BIN
+2 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-setup.png
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-57 Bytes
(100%)
static/images/blog/appwrite-decoded-dennis/dennis-youtube.png
Oops, something went wrong.
Binary file modified
BIN
-32 Bytes
(100%)
static/images/blog/appwrite-decoded-dylan/appwrite-decoded-dylan-blog-cover.png
Oops, something went wrong.
Binary file modified
BIN
-3 Bytes
(100%)
static/images/blog/appwrite-decoded-dylan/appwrite-decoded-dylan-camp3.png
Oops, something went wrong.
Binary file modified
BIN
+4 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-campus-expert.png
Oops, something went wrong.
Binary file modified
BIN
-82 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-career-update.png
Oops, something went wrong.
Binary file modified
BIN
-3 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-conference-appwrite.png
Oops, something went wrong.
Binary file modified
BIN
+41 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-conference.png
Oops, something went wrong.
Binary file modified
BIN
-75 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-cover.png
Oops, something went wrong.
Binary file modified
BIN
-112 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-git.png
Oops, something went wrong.
Binary file modified
BIN
-6 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-hackathon.png
Oops, something went wrong.
Binary file modified
BIN
-53 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-post-network.png
Oops, something went wrong.
Binary file modified
BIN
+18 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-remote-setting.png
Oops, something went wrong.
Binary file modified
BIN
-6 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-team-engineering.png
Oops, something went wrong.
Binary file modified
BIN
-46 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-team-two.png
Oops, something went wrong.
Binary file modified
BIN
-82 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-team.png
Oops, something went wrong.
Binary file modified
BIN
-41 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-tech-interviews.png
Oops, something went wrong.
Binary file modified
BIN
+20 Bytes
(100%)
static/images/blog/appwrite-decoded-khushboo/khushboo-with-eldad.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file modified
BIN
-910 KB
(47%)
static/images/blog/best-ios-android-app-development-platform/cover.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.