PERF: summary serializer for events list (#484)
* PERF: summary serializer for events list
This commit is contained in:
parent
61ec1f7545
commit
87793eac8d
|
|
@ -8,7 +8,7 @@ module DiscoursePostEvent
|
|||
render json:
|
||||
ActiveModel::ArraySerializer.new(
|
||||
@events,
|
||||
each_serializer: EventSerializer,
|
||||
each_serializer: EventSummarySerializer,
|
||||
scope: guardian,
|
||||
).as_json
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscoursePostEvent
|
||||
class EventSummarySerializer < ApplicationSerializer
|
||||
attributes :id
|
||||
attributes :starts_at
|
||||
attributes :ends_at
|
||||
attributes :timezone
|
||||
attributes :post
|
||||
attributes :name
|
||||
attributes :category_id
|
||||
|
||||
# lightweight post object containing
|
||||
# only needed info for client
|
||||
def post
|
||||
{
|
||||
id: object.post.id,
|
||||
post_number: object.post.post_number,
|
||||
url: object.post.url,
|
||||
topic: {
|
||||
id: object.post.topic.id,
|
||||
title: object.post.topic.title,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
def category_id
|
||||
object.post.topic.category_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
require "rails_helper"
|
||||
|
||||
describe DiscoursePostEvent::EventSummarySerializer do
|
||||
before do
|
||||
SiteSetting.calendar_enabled = true
|
||||
SiteSetting.discourse_post_event_enabled = true
|
||||
end
|
||||
|
||||
fab!(:category)
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:post) { Fabricate(:post, topic: topic) }
|
||||
fab!(:event) { Fabricate(:event, post: post) }
|
||||
|
||||
it "returns the event summary" do
|
||||
json = DiscoursePostEvent::EventSummarySerializer.new(event, scope: Guardian.new).as_json
|
||||
summary = json[:event_summary]
|
||||
expect(summary[:starts_at]).to eq(event.starts_at)
|
||||
expect(summary[:ends_at]).to eq(event.ends_at)
|
||||
expect(summary[:timezone]).to eq(event.timezone)
|
||||
expect(summary[:name]).to eq(event.name)
|
||||
expect(summary[:post][:url]).to eq(post.url)
|
||||
expect(summary[:post][:topic][:title]).to eq(topic.title)
|
||||
expect(summary[:category_id]).to eq(category.id)
|
||||
end
|
||||
end
|
||||
|
|
@ -8,27 +8,9 @@ const eventsPretender = (server, helper) => {
|
|||
events: [
|
||||
{
|
||||
id: 67501,
|
||||
creator: {
|
||||
id: 1500588,
|
||||
username: "foobar",
|
||||
name: null,
|
||||
avatar_template: "/user_avatar/localhost/foobar/{size}/1913_2.png",
|
||||
assign_icon: "user-plus",
|
||||
assign_path: "/u/foobar/activity/assigned",
|
||||
},
|
||||
sample_invitees: [],
|
||||
watching_invitee: null,
|
||||
starts_at: "2022-04-25T15:14:00.000Z",
|
||||
ends_at: "2022-04-30T16:14:00.000Z",
|
||||
timezone: "Asia/Calcutta",
|
||||
stats: {
|
||||
going: 0,
|
||||
interested: 0,
|
||||
not_going: 0,
|
||||
invited: 0,
|
||||
},
|
||||
status: "public",
|
||||
raw_invitees: ["trust_level_0"],
|
||||
post: {
|
||||
id: 67501,
|
||||
post_number: 1,
|
||||
|
|
@ -39,18 +21,6 @@ const eventsPretender = (server, helper) => {
|
|||
},
|
||||
},
|
||||
name: "Awesome Event",
|
||||
can_act_on_discourse_post_event: true,
|
||||
can_update_attendance: true,
|
||||
is_expired: false,
|
||||
is_ongoing: false,
|
||||
should_display_invitees: false,
|
||||
url: null,
|
||||
custom_fields: {},
|
||||
is_public: true,
|
||||
is_private: false,
|
||||
is_standalone: false,
|
||||
reminders: [],
|
||||
recurrence: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,28 +18,9 @@ acceptance("Discourse Calendar - Category Events Calendar", function (needs) {
|
|||
events: [
|
||||
{
|
||||
id: 67501,
|
||||
creator: {
|
||||
id: 1500588,
|
||||
username: "foobar",
|
||||
name: null,
|
||||
avatar_template:
|
||||
"/user_avatar/localhost/foobar/{size}/1913_2.png",
|
||||
assign_icon: "user-plus",
|
||||
assign_path: "/u/foobar/activity/assigned",
|
||||
},
|
||||
sample_invitees: [],
|
||||
watching_invitee: null,
|
||||
starts_at: "2022-04-25T15:14:00.000Z",
|
||||
ends_at: "2022-04-30T16:14:00.000Z",
|
||||
timezone: "Asia/Calcutta",
|
||||
stats: {
|
||||
going: 0,
|
||||
interested: 0,
|
||||
not_going: 0,
|
||||
invited: 0,
|
||||
},
|
||||
status: "public",
|
||||
raw_invitees: ["trust_level_0"],
|
||||
post: {
|
||||
id: 67501,
|
||||
post_number: 1,
|
||||
|
|
@ -50,18 +31,6 @@ acceptance("Discourse Calendar - Category Events Calendar", function (needs) {
|
|||
},
|
||||
},
|
||||
name: "Awesome Event",
|
||||
can_act_on_discourse_post_event: true,
|
||||
can_update_attendance: true,
|
||||
is_expired: false,
|
||||
is_ongoing: false,
|
||||
should_display_invitees: false,
|
||||
url: null,
|
||||
custom_fields: {},
|
||||
is_public: true,
|
||||
is_private: false,
|
||||
is_standalone: false,
|
||||
reminders: [],
|
||||
recurrence: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,28 +38,9 @@ acceptance("Discourse Calendar - Upcoming Events Calendar", function (needs) {
|
|||
events: [
|
||||
{
|
||||
id: 67501,
|
||||
creator: {
|
||||
id: 1500588,
|
||||
username: "foobar",
|
||||
name: null,
|
||||
avatar_template:
|
||||
"/user_avatar/localhost/foobar/{size}/1913_2.png",
|
||||
assign_icon: "user-plus",
|
||||
assign_path: "/u/foobar/activity/assigned",
|
||||
},
|
||||
sample_invitees: [],
|
||||
watching_invitee: null,
|
||||
starts_at: tomorrow(),
|
||||
ends_at: null,
|
||||
timezone: "Asia/Calcutta",
|
||||
stats: {
|
||||
going: 0,
|
||||
interested: 0,
|
||||
not_going: 0,
|
||||
invited: 0,
|
||||
},
|
||||
status: "public",
|
||||
raw_invitees: ["trust_level_0"],
|
||||
post: {
|
||||
id: 67501,
|
||||
post_number: 1,
|
||||
|
|
@ -70,44 +51,13 @@ acceptance("Discourse Calendar - Upcoming Events Calendar", function (needs) {
|
|||
},
|
||||
},
|
||||
name: "Awesome Event",
|
||||
can_act_on_discourse_post_event: true,
|
||||
can_update_attendance: true,
|
||||
is_expired: false,
|
||||
is_ongoing: true,
|
||||
should_display_invitees: false,
|
||||
url: null,
|
||||
custom_fields: {},
|
||||
is_public: true,
|
||||
is_private: false,
|
||||
is_standalone: false,
|
||||
reminders: [],
|
||||
recurrence: null,
|
||||
category_id: 1,
|
||||
},
|
||||
{
|
||||
id: 67502,
|
||||
creator: {
|
||||
id: 1500588,
|
||||
username: "foobar",
|
||||
name: null,
|
||||
avatar_template:
|
||||
"/user_avatar/localhost/foobar/{size}/1913_2.png",
|
||||
assign_icon: "user-plus",
|
||||
assign_path: "/u/foobar/activity/assigned",
|
||||
},
|
||||
sample_invitees: [],
|
||||
watching_invitee: null,
|
||||
starts_at: tomorrow(),
|
||||
ends_at: null,
|
||||
timezone: "Asia/Calcutta",
|
||||
stats: {
|
||||
going: 0,
|
||||
interested: 0,
|
||||
not_going: 0,
|
||||
invited: 0,
|
||||
},
|
||||
status: "public",
|
||||
raw_invitees: ["trust_level_0"],
|
||||
post: {
|
||||
id: 67501,
|
||||
post_number: 1,
|
||||
|
|
@ -118,18 +68,6 @@ acceptance("Discourse Calendar - Upcoming Events Calendar", function (needs) {
|
|||
},
|
||||
},
|
||||
name: "Another Awesome Event",
|
||||
can_act_on_discourse_post_event: true,
|
||||
can_update_attendance: true,
|
||||
is_expired: false,
|
||||
is_ongoing: true,
|
||||
should_display_invitees: false,
|
||||
url: null,
|
||||
custom_fields: {},
|
||||
is_public: true,
|
||||
is_private: false,
|
||||
is_standalone: false,
|
||||
reminders: [],
|
||||
recurrence: null,
|
||||
category_id: 2,
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -214,27 +214,9 @@ function twoEventsResponseHandler() {
|
|||
events: [
|
||||
{
|
||||
id: 67501,
|
||||
creator: {
|
||||
id: 1500588,
|
||||
username: "foobar",
|
||||
name: null,
|
||||
avatar_template: "/user_avatar/localhost/foobar/{size}/1913_2.png",
|
||||
assign_icon: "user-plus",
|
||||
assign_path: "/u/foobar/activity/assigned",
|
||||
},
|
||||
sample_invitees: [],
|
||||
watching_invitee: null,
|
||||
starts_at: tomorrowAllDay,
|
||||
ends_at: null,
|
||||
timezone: "Asia/Calcutta",
|
||||
stats: {
|
||||
going: 0,
|
||||
interested: 0,
|
||||
not_going: 0,
|
||||
invited: 0,
|
||||
},
|
||||
status: "public",
|
||||
raw_invitees: ["trust_level_0"],
|
||||
post: {
|
||||
id: 67501,
|
||||
post_number: 1,
|
||||
|
|
@ -245,43 +227,13 @@ function twoEventsResponseHandler() {
|
|||
},
|
||||
},
|
||||
name: "Awesome Event",
|
||||
can_act_on_discourse_post_event: true,
|
||||
can_update_attendance: true,
|
||||
is_expired: false,
|
||||
is_ongoing: true,
|
||||
should_display_invitees: false,
|
||||
url: null,
|
||||
custom_fields: {},
|
||||
is_public: true,
|
||||
is_private: false,
|
||||
is_standalone: false,
|
||||
reminders: [],
|
||||
recurrence: null,
|
||||
category_id: 1,
|
||||
},
|
||||
{
|
||||
id: 67502,
|
||||
creator: {
|
||||
id: 1500588,
|
||||
username: "foobar",
|
||||
name: null,
|
||||
avatar_template: "/user_avatar/localhost/foobar/{size}/1913_2.png",
|
||||
assign_icon: "user-plus",
|
||||
assign_path: "/u/foobar/activity/assigned",
|
||||
},
|
||||
sample_invitees: [],
|
||||
watching_invitee: null,
|
||||
starts_at: nextMonth,
|
||||
ends_at: null,
|
||||
timezone: "Asia/Calcutta",
|
||||
stats: {
|
||||
going: 0,
|
||||
interested: 0,
|
||||
not_going: 0,
|
||||
invited: 0,
|
||||
},
|
||||
status: "public",
|
||||
raw_invitees: ["trust_level_0"],
|
||||
post: {
|
||||
id: 67501,
|
||||
post_number: 1,
|
||||
|
|
@ -292,18 +244,6 @@ function twoEventsResponseHandler() {
|
|||
},
|
||||
},
|
||||
name: "Another Awesome Event",
|
||||
can_act_on_discourse_post_event: true,
|
||||
can_update_attendance: true,
|
||||
is_expired: false,
|
||||
is_ongoing: true,
|
||||
should_display_invitees: false,
|
||||
url: null,
|
||||
custom_fields: {},
|
||||
is_public: true,
|
||||
is_private: false,
|
||||
is_standalone: false,
|
||||
reminders: [],
|
||||
recurrence: null,
|
||||
category_id: 2,
|
||||
},
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue