PERF: Cache categories in Site model take 3.

Previous attempt resulted in custom fields going missing in the
serialized output.

This reverts commit 83a6ad32ff.
This commit is contained in:
Alan Guo Xiang Tan
2021-06-23 15:21:11 +08:00
parent fd2aab09ef
commit 0e4b8c5318
9 changed files with 181 additions and 30 deletions

View File

@@ -142,6 +142,11 @@ module HasCustomFields
super
end
def on_custom_fields_change
# Callback when custom fields have changed
# Override in model
end
def custom_fields_preloaded?
!!@preloaded_custom_fields
end
@@ -197,8 +202,11 @@ module HasCustomFields
if row_count == 0
_custom_fields.create!(name: k, value: v)
end
custom_fields[k.to_s] = v # We normalize custom_fields as strings
end
on_custom_fields_change
end
def save_custom_fields(force = false)
@@ -253,6 +261,7 @@ module HasCustomFields
end
end
on_custom_fields_change
refresh_custom_fields_from_db
end
end