Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/831
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Sep 1, 2024
1 parent 14a7c19 commit 2e8e431
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
22 changes: 18 additions & 4 deletions lib/activities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,20 @@ defmodule Bonfire.Social.Activities do
do:
query
|> proload(
activity: [labelled: {"labelled_", [:post_content, :media, subject: [:profile]]}]
activity: [
labelled:
{"labelled_",
[
:post_content
# :media,
# subject: [:profile]
]}
]
),
else: query

# NOTE: media attached to the label should be loaded separately as there can be several

# proload query, activity: [:media] # FYI: proloading media only queries one attachment
:with_seen ->
query_preload_seen(query, opts)
Expand Down Expand Up @@ -851,9 +861,7 @@ defmodule Bonfire.Social.Activities do
[:media, :sensitive]

:maybe_with_labelled ->
if Extend.module_enabled?(Bonfire.Label, opts),
do: [labelled: [:post_content, :media, subject: [:profile]]],
else: []
maybe_with_labelled()

:with_seen ->
subquery = subquery_preload_seen(opts)
Expand All @@ -862,6 +870,12 @@ defmodule Bonfire.Social.Activities do
end
end

def maybe_with_labelled do
if Extend.extension_enabled?(:bonfire_label),
do: [labelled: [:post_content, :media, subject: [:profile]]],
else: []
end

defp maybe_preload_reply_to(opts) do
# If the root replied to anything, fetch that and its creator too. e.g.
# * Alice's post that replied to Bob's post
Expand Down
34 changes: 20 additions & 14 deletions lib/feed_activities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,6 @@ defmodule Bonfire.Social.FeedActivities do

result
end
# TODO: where best to do these postloads? and try to optimise into one call
|> Bonfire.Common.Needles.Preload.maybe_preload_nested_pointers(
[activity: [replied: [:reply_to]]],
opts
)
|> Bonfire.Common.Needles.Preload.maybe_preload_nested_pointers(
[activity: [:object]],
opts
)

# run post-preloads to follow pointers and catch anything else missing - TODO: only follow some pointers
# |> Activities.activity_preloads(e(opts, :preload, :feed), opts |> Keyword.put_new(:follow_pointers, true))
end
end

Expand Down Expand Up @@ -707,7 +695,25 @@ defmodule Bonfire.Social.FeedActivities do
:edges,
edges
|> maybe_dedup_feed_objects(opts)
# |> Activities.activity_preloads(post_preloads, opts)
# TODO: where best to do these postloads? and try to optimise into one call

|> Bonfire.Common.Needles.Preload.maybe_preload_nested_pointers(
[activity: [replied: [:reply_to]]],
opts
)
|> Bonfire.Common.Needles.Preload.maybe_preload_nested_pointers(
[activity: [:object]],
opts
)
|> repo().maybe_preload(
# FIXME: this should happen in `Activities.activity_preloads`
[activity: Activities.maybe_with_labelled()],
opts |> Keyword.put_new(:follow_pointers, false)
)

# run post-preloads to follow pointers and catch anything else missing - TODO: only follow some pointers
# |> Activities.activity_preloads(e(opts, :preload, :feed), opts |> Keyword.put_new(:follow_pointers, true))
# |> Activities.activity_preloads(e(opts, :preload, :feed), opts |> Keyword.put_new(:follow_pointers, false))
)
end

Expand Down Expand Up @@ -959,7 +965,7 @@ defmodule Bonfire.Social.FeedActivities do
debug("include labelling for all")
[]
else
debug("do not include labelling")
debug("do not include labelling as activities")
[:label]
end ++
if opts[:include_flags] == :moderators and
Expand Down
4 changes: 2 additions & 2 deletions lib/post_contents.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ defmodule Bonfire.Social.PostContents do
#Ecto.Changeset<...>
"""
def cast(changeset, attrs, creator, boundary, opts) do
has_images = is_list(attrs[:uploaded_media]) and length(attrs[:uploaded_media]) > 0
has_media = not is_nil(e(attrs, :uploaded_media, nil) || e(attrs, :links, nil))

changeset
|> repo().maybe_preload(:post_content)
|> Changeset.cast(%{post_content: maybe_prepare_contents(attrs, creator, boundary, opts)}, [])
|> Changeset.cast_assoc(:post_content,
required: !has_images,
required: !has_media,
with: &changeset/2
# with: (if changeset.action==:upsert, do: &changeset_update/2, else: &changeset/2)
)
Expand Down
6 changes: 6 additions & 0 deletions lib/threads.ex
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,14 @@ defmodule Bonfire.Social.Threads do
# preloaded after so we can get more than 1
|> repo().maybe_preload(
# :pinned,
# FIXME: this should happen via `Activities.activity_preloads`
activity: [:media]
)
|> repo().maybe_preload(
# FIXME: this should happen via `Activities.activity_preloads`
[activity: Activities.maybe_with_labelled()],
opts |> Keyword.put_new(:follow_pointers, false)
)

# |> repo().many # without pagination
# |> debug("thread")
Expand Down

0 comments on commit 2e8e431

Please sign in to comment.