From ab3a66fad7eea982b7c46ea3916d86c50b5c1821 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 17 Nov 2023 15:31:23 +0100 Subject: [PATCH] Hash the contents as that is much faster Hashing the file takes over 0.100ms (due to having to load the file again), which arguably is not much, but considering that hashing the content already stored in memory is less than 0.007ms which is an order of magnitude faster, for something that does not affect the feature. --- packages/realtime-compiler/resources/live-edit.blade.php | 2 +- packages/realtime-compiler/src/Http/LiveEditController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/realtime-compiler/resources/live-edit.blade.php b/packages/realtime-compiler/resources/live-edit.blade.php index 9c585a90323..e259c391dcd 100644 --- a/packages/realtime-compiler/resources/live-edit.blade.php +++ b/packages/realtime-compiler/resources/live-edit.blade.php @@ -21,7 +21,7 @@ - + diff --git a/packages/realtime-compiler/src/Http/LiveEditController.php b/packages/realtime-compiler/src/Http/LiveEditController.php index 96ba6669aa5..0c30f1aded7 100644 --- a/packages/realtime-compiler/src/Http/LiveEditController.php +++ b/packages/realtime-compiler/src/Http/LiveEditController.php @@ -50,7 +50,7 @@ protected function handleRequest(): Response $this->abort(400, 'Page is not a markdown page'); } - if (! $force && hash_file('sha256', $page->getSourcePath()) !== $currentContentHash) { + if (! $force && hash('sha256', $page->markdown()->body()) !== $currentContentHash) { $this->abort(409, 'Content has changed in another window'); }