Bonfire.Social.API.UserInteractionsDataloader (Bonfire v1.0.1-social-alpha.28)

View Source

Dataloader.KV source for batch-loading user interaction states (liked, boosted, bookmarked). Prevents N+1 queries when loading feed activities in GraphQL.

This batches interaction checks per activity, only querying for the specific activities in the current feed, rather than loading ALL of a user's interactions.

Summary

Functions

Batch check if user has performed a specific interaction on multiple activities. Uses a single query to check all user+activity pairs for the given interaction type.

Creates a new Dataloader.KV source for user interactions.

Fetch function for Dataloader.KV. Receives a batch name and a list of argument maps. Returns a map of args => boolean result.

Functions

batch_check_interaction(args, interaction_module)

Batch check if user has performed a specific interaction on multiple activities. Uses a single query to check all user+activity pairs for the given interaction type.

Examples

batch_check_interaction(
  [%{user_id: "user1", activity_id: "act1"}],
  Bonfire.Data.Social.Like
)
# => %{%{user_id: "user1", activity_id: "act1"} => true}

data()

Creates a new Dataloader.KV source for user interactions.

fetch(arg1, args)

Fetch function for Dataloader.KV. Receives a batch name and a list of argument maps. Returns a map of args => boolean result.

Examples

# Dataloader batches requests like:
fetch(:liked, [
  %{user_id: "user123", activity_id: "act1"},
  %{user_id: "user123", activity_id: "act2"}
])
# => %{
#   %{user_id: "user123", activity_id: "act1"} => true,
#   %{user_id: "user123", activity_id: "act2"} => false
# }