-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Create Update Feed #117
base: master
Are you sure you want to change the base?
Conversation
…re main objects for the update-feed feature
…its from event model
assert.same 0, #followings | ||
assert.same 0, #events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails because of the comment mentioned above in flows/followings.moon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently "only" in tests the event created in follow_object
can't be found and isn't deleted.
flows/followings.moon
Outdated
@@ -41,5 +51,6 @@ class FollowingsFlow extends Flow | |||
"follow", | |||
@current_user | |||
|
|||
following\delete! | |||
event\delete! if event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When running tests, if this if
gets removed, the test fails with a nil
. That's because the find
of the event object fails. I'm currently investigating it but I have no clue yet.
…information about the events in the index page
… everyone who follows a model
There are a few details missing here besides a proper UI for the timeline.
|
c89cdda
to
2a4e099
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start, here's my feedback from first pass
widgets/timeline_events.moon
Outdated
inner_content: => | ||
ul -> | ||
for event in *@current_user\timeline! | ||
row_event = Events\find(event.event_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both of these will cause the n+1 queries issue: http://leafo.net/guides/postgresql-preloading.html#avoiding-n-and-1-queries
the solution in this case is to use the preload
function ahead of time, then use the relation getter to get each object. You'll need to add the missing relation on the timeline events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently preloading it in timeline
method instead of in the widget as I guess it's cleaner to only have presentation in a widget.
widgets/timeline_events.moon
Outdated
|
||
switch Events\model_for_object_type(row_event.object_object_type) | ||
when Modules | ||
mod = Modules\find row_event.object_object_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be preloaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are broken because the nested preload of object
in timeline.event
isn't working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
widgets/timeline_events.moon
Outdated
href: @url_for("module", user: user.slug, module: mod.name) | ||
}, mod\name_for_display! | ||
when Users | ||
usr = Users\find row_event.object_object_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be preloaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
if Events\model_for_object_type(event.object_object_type) == Users | ||
@@create(Users\find(event.object_object_id), event) | ||
|
||
@user_timeline: (user) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you probably want to either paginate this, or limit to something reasonable like 50 for the time being
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm limiting by 50 but I plan to add pagination soon.
models/timeline_events.moon
Outdated
@deliver: (user, event) => | ||
switch event.event_type | ||
when Events.event_types.update | ||
followers = Followings\select "where object_id = ?", event.object_object_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
object_type
should be specified when querying by object_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
models/timeline_events.moon
Outdated
class TimelineEvents extends Model | ||
@primary_key: { "user_id", "event_id" } | ||
|
||
@create: (user, event) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use an opts
argument for all model creation, with assertions on required fields. I know there are some models in the codebase that use this style, but I've been updating them as I see them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
models/timeline_events.moon
Outdated
@@ -0,0 +1,32 @@ | |||
db = require "lapis.db" | |||
import Model from require "lapis.db.model" | |||
import Events, Followings, Users from require "models" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to avoid putting module requires on the top level, and instead in the methods, to prevent any issues with circular dependencies in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
models/events.moon
Outdated
}} | ||
} | ||
|
||
@create: (user, object, event_type) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use an opts argument for all model creation, with assertions on required fields. I know there are some models in the codebase that use this style, but I've been updating them as I see them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
migrations.moon
Outdated
{"event_type", enum} | ||
{"source_user_id", enum} | ||
{"object_object_id", enum} | ||
{"object_object_type", foreign_key} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
migrations.moon
Outdated
create_table "events", { | ||
{"id", serial} | ||
{"event_type", enum} | ||
{"source_user_id", enum} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two should be foreign_key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source_user_id
really should be a foreign key but event_type
too ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure if I understand what columns should be changed. I've changed the way I thought it made sense, could you check the changes out ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
flows/followings.moon
Outdated
@@ -12,7 +12,8 @@ class FollowingsFlow extends Flow | |||
super ... | |||
assert_error @current_user, "must be logged in" | |||
|
|||
follow_object: (object, type) => | |||
follow_object: (object, type) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation looks messed up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
flows/followings.moon
Outdated
@@ -25,6 +26,9 @@ class FollowingsFlow extends Flow | |||
Notifications\notify_for target_user, object, | |||
type, @current_user | |||
|
|||
event = Events\create(@current_user, object, Events.event_types.subscription) | |||
TimelineEvents\deliver(@current_user, event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure you're delivering the event to the right person? If I follow someone then I would expect an event to show up on their timeline?
Additionally, we already have notifications for follows, do we want to also have timeline events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends, maybe not sending the event to the followed timeline is better (and save some processing).
Yeah, for followings, I guess the notifications that are present are enough.
Do you an idea about what kind of stuff show be added to a timeline ?
flows/followings.moon
Outdated
@@ -35,6 +39,13 @@ class FollowingsFlow extends Flow | |||
type: Followings.types\for_db type | |||
} | |||
|
|||
event = Events\find { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so when you unfollow something you'd like all the events cleaned from your timeline (eg. they pushed 10 new updates to their module) Given that, you'll need to use select
to handle something like that, since find
only returns one row. Also, you don't want to delete the event
, but you want to delete the timeline_event
the logic to do this is semi-complicated, so maybe it could be a method on a model, or in a timeline flow
d4d0fa3
to
ab657c7
Compare
d990483
to
19c4ef4
Compare
spec/applications/modules_spec.moon
Outdated
@@ -6,13 +6,13 @@ import request_as from require "spec.helpers" | |||
factory = require "spec.factory" | |||
|
|||
|
|||
import Modules, Versions, Followings, Users, Notifications, NotificationObjects from require "models" | |||
import Modules, Versions, Events, Followings, Users, Notifications, NotificationObjects from require "spec.models" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec.models
adds a before_each
to truncate, so you should move this entire line into the describe, and then you can remove the redundant trucate_tables
method call in the existing before_each
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
spec/models/events_spec.moon
Outdated
Modules | ||
Users from require "spec.models" | ||
|
||
import Events, TimelineEvents from require "models" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convert this to require from spec.models
and put it inside the describe
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
spec/models/events_spec.moon
Outdated
object: module | ||
event_type: Events.event_types.subscription | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
…this fixed the broken preloads in timeline_events widget too
b55129b
to
8517657
Compare
…liver to timelines and removal of events from timeline (in case of unsubscription)
d5daf4b
to
714cbcf
Compare
714cbcf
to
6bd7539
Compare
This PR has the goal of creating a update feed in LuaRocks, basically showing the users whats new from the modules and users they follow.