Skip to content

Commit

Permalink
using preload correctly with lapis updated version
Browse files Browse the repository at this point in the history
  • Loading branch information
aajjbb committed Aug 13, 2017
1 parent a9206c5 commit d990483
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 8 additions & 2 deletions models/timeline_events.moon
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class TimelineEvents extends Model
when Events.event_types.update
followers = Followings\select "where object_id = ? and object_type = ?", event.object_object_id, event.object_object_type

Followings\preload_relation followers, "source_user"

for users in *followers
follower_user = Users\find users.source_user_id
follower_user = users.source_user
@@create({
user_id: follower_user.id
event_id: event
Expand All @@ -48,4 +50,8 @@ class TimelineEvents extends Model
})

@user_timeline: (user) =>
@@select "where user_id = ?", user.id
import preload from require "lapis.db.model"
timeline = @@select "where user_id = ? limit 50", user.id
preload timeline, "user"
preload timeline, event: "object"
return timeline
9 changes: 3 additions & 6 deletions widgets/timeline_events.moon
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ class TimelineEvents extends require "widgets.base"

inner_content: =>
ul ->
import preload from require "lapis.db.model"
timeline = @current_user\timeline!
preload timeline, event: "object"
preload timeline, "user"

for event in *timeline
row_event = event.event
user = event.user
for timeline_event in *timeline
row_event = timeline_event.event
user = timeline_event.user

message = switch row_event.event_type
when Events.event_types.subscription
Expand Down

0 comments on commit d990483

Please sign in to comment.