From b3daba77bd523e9acc1fe5211d9fa3cdd21f4edf Mon Sep 17 00:00:00 2001 From: or-else Date: Mon, 26 Apr 2021 21:36:49 -0700 Subject: [PATCH] cherrypicking support for browsable subscriptions --- server/db/mongodb/adapter.go | 6 +++--- server/db/mysql/adapter.go | 11 ++++++----- server/db/rethinkdb/adapter.go | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/server/db/mongodb/adapter.go b/server/db/mongodb/adapter.go index 0070cdd5d..5f8f37893 100644 --- a/server/db/mongodb/adapter.go +++ b/server/db/mongodb/adapter.go @@ -1285,9 +1285,9 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) ( } limit := a.maxResults if opts != nil { - // Ignore IfModifiedSince - we must return all entries - // Those unmodified will be stripped of Public & Private. - + if opts.IfModifiedSince != nil { + filter["updatedat"] = b.M{"$gt": opts.IfModifiedSince} + } if opts.Topic != "" { filter["topic"] = opts.Topic } diff --git a/server/db/mysql/adapter.go b/server/db/mysql/adapter.go index 7eacf101c..6db68efb7 100644 --- a/server/db/mysql/adapter.go +++ b/server/db/mysql/adapter.go @@ -1428,9 +1428,10 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) ( limit := a.maxResults if opts != nil { - // Ignore IfModifiedSince - we must return all entries - // Those unmodified will be stripped of Public & Private. - + if opts.IfModifiedSince != nil { + q += " AND updatedat>?" + args = append(args, opts.IfModifiedSince) + } if opts.Topic != "" { q += " AND topic=?" args = append(args, opts.Topic) @@ -1597,7 +1598,7 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) ( } // UsersForTopic loads users subscribed to the given topic. -// The difference between UsersForTopic vs SubsForTopic is that the former loads user.public, +// The difference between UsersForTopic vs SubsForTopic is that the former loads user.Public, // the latter does not. func (a *adapter) UsersForTopic(topic string, keepDeleted bool, opts *t.QueryOpt) ([]t.Subscription, error) { tcat := t.GetTopicCat(topic) @@ -1624,7 +1625,7 @@ func (a *adapter) UsersForTopic(topic string, keepDeleted bool, opts *t.QueryOpt limit := a.maxResults var oneUser t.Uid if opts != nil { - // Ignore IfModifiedSince - we must return all entries + // Ignore IfModifiedSince: loading all entries because a topic cannot have too many subscribers. // Those unmodified will be stripped of Public & Private. if !opts.User.IsZero() { diff --git a/server/db/rethinkdb/adapter.go b/server/db/rethinkdb/adapter.go index 779d9b56a..d778e2ddc 100644 --- a/server/db/rethinkdb/adapter.go +++ b/server/db/rethinkdb/adapter.go @@ -1091,9 +1091,9 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) ( } limit := a.maxResults if opts != nil { - // Ignore IfModifiedSince - we must return all entries - // Those unmodified will be stripped of Public & Private. - + if opts.IfModifiedSince != nil { + q = q.Filter(rdb.Row.Field("UpdatedAt").Gt(opts.IfModifiedSince)) + } if opts.Topic != "" { q = q.Filter(rdb.Row.Field("Topic").Eq(opts.Topic)) }