FIX: limit visible revisions history to last 100 (#12946)

FIX: limit visible revisions history to last 100 (#12946)

This is done to prevent spike memory usage when the number of revisions is very large (thousands) and the post has a significant length.

diff --git a/app/serializers/post_revision_serializer.rb b/app/serializers/post_revision_serializer.rb
index 415999e..1791c38 100644
--- a/app/serializers/post_revision_serializer.rb
+++ b/app/serializers/post_revision_serializer.rb
@@ -190,7 +190,12 @@ class PostRevisionSerializer < ApplicationSerializer
   def all_revisions
     return @all_revisions if @all_revisions
 
-    post_revisions = PostRevision.where(post_id: object.post_id).order(:number).to_a
+    post_revisions = PostRevision
+      .where(post_id: object.post_id)
+      .order(number: :desc)
+      .limit(99)
+      .to_a
+      .reverse
 
     latest_modifications = {
       "raw" => [post.raw],
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 0485093..280f267 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3374,7 +3374,7 @@ en:
       one: "user"
       other: "users"
     category_title: "Category"
-    history: "History"
+    history: "History, last 100 revisions"
     changed_by: "by %{author}"
 
     raw_email:

GitHub sha: b0e9c6e1

This commit appears in #12946 which was approved by ZogStriP. It was merged by jjaffeux.