Skip to content

Commit 00aa75f

Browse files
authored
Show service summaries in recommendations in team-building (keybase#20236)
Move ServiceMapper to G so it's available in InterestingPeople RPC handler. Because we want this RPC not to make any extra network calls, we use ServiceMapper with "no network budget", so it will only use what's in cache. However this is a problem, because unless you've had a user in contacts, you won't have their service summary in cache. This is solved by caching service summaries coming in libkb/loaduser.go (in idTable.remoteProofLinks). Because InterestingPeople returns users you either chatted with or follow, you usually had to interact with them beforehand, and therefore load them.
1 parent 40c2b9d commit 00aa75f

20 files changed

Lines changed: 187 additions & 24 deletions

File tree

‎go/bind/extension.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func ExtensionInit(homeDir string, mobileSharedHome string, logFile string, runM
159159

160160
// 10k uid -> FullName cache entries allowed
161161
kbCtx.SetUIDMapper(uidmap.NewUIDMap(10000))
162+
kbCtx.SetServiceSummaryMapper(uidmap.NewOfflineServiceSummaryMap())
162163
usage := libkb.Usage{
163164
Config: true,
164165
API: true,

‎go/bind/keybase.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func Init(homeDir, mobileSharedHome, logFile, runModeStr string,
174174

175175
// 10k uid -> FullName cache entries allowed
176176
kbCtx.SetUIDMapper(uidmap.NewUIDMap(10000))
177+
kbCtx.SetServiceSummaryMapper(uidmap.NewServiceSummaryMap(1000))
177178
usage := libkb.Usage{
178179
Config: true,
179180
API: true,

‎go/client/cmd_interesting_people.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func (c *CmdInterestingPeople) ParseArgv(ctx *cli.Context) error {
2222
}
2323

2424
func (c *CmdInterestingPeople) Run() error {
25-
2625
cli, err := GetUserClient(c.G())
2726
if err != nil {
2827
return err
@@ -36,6 +35,7 @@ func (c *CmdInterestingPeople) Run() error {
3635
for _, user := range users {
3736
_ = c.G().UI.GetTerminalUI().Output(user.Username + "\n")
3837
}
38+
3939
return nil
4040
}
4141
func NewCmdInterestingPeopleRunner(g *libkb.GlobalContext) *CmdInterestingPeople {

‎go/externalstest/test_common.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func SetupTest(tb libkb.TestingTB, name string, depthIgnored int) (tc libkb.Test
1919

2020
tc.G.SetProofServices(externals.NewProofServices(tc.G))
2121
tc.G.SetUIDMapper(uidmap.NewUIDMap(10000))
22+
tc.G.SetServiceSummaryMapper(uidmap.NewServiceSummaryMap(1000))
2223
pvl.NewPvlSourceAndInstall(tc.G)
2324
externals.NewParamProofStoreAndInstall(tc.G)
2425
return tc

‎go/keybase/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func mainInner(g *libkb.GlobalContext, startupErrors []error) error {
262262
func configOtherLibraries(g *libkb.GlobalContext) error {
263263
// Set our UID -> Username mapping service
264264
g.SetUIDMapper(uidmap.NewUIDMap(g.Env.GetUIDMapFullNameCacheSize()))
265+
g.SetServiceSummaryMapper(uidmap.NewServiceSummaryMap(1000))
265266
return nil
266267
}
267268

‎go/libkb/globals.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ type GlobalContext struct {
123123
UIRouter UIRouter // How to route UIs
124124
proofServices ExternalServicesCollector // All known external services
125125
UIDMapper UIDMapper // maps from UID to Usernames
126+
ServiceMapper ServiceSummaryMapper // handles and caches batch requests for service summaries
126127
ExitCode keybase1.ExitCode // Value to return to OS on Exit()
127128
RateLimits *RateLimits // tracks the last time certain actions were taken
128129
clockMu *sync.Mutex // protects Clock
@@ -288,6 +289,10 @@ func (g *GlobalContext) SetUIDMapper(u UIDMapper) {
288289
g.UIDMapper = u
289290
}
290291

292+
func (g *GlobalContext) SetServiceSummaryMapper(u ServiceSummaryMapper) {
293+
g.ServiceMapper = u
294+
}
295+
291296
func (g *GlobalContext) SetUIRouter(u UIRouter) {
292297
g.UIRouter = u
293298
}

‎go/libkb/interfaces.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ type UserServiceSummaryPackage struct {
10081008
type ServiceSummaryMapper interface {
10091009
MapUIDsToServiceSummaries(ctx context.Context, g UIDMapperContext, uids []keybase1.UID, freshness time.Duration,
10101010
networkTimeBudget time.Duration) map[keybase1.UID]UserServiceSummaryPackage
1011+
InformOfServiceSummary(ctx context.Context, g UIDMapperContext, uid keybase1.UID, summary UserServiceSummary) error
10111012
}
10121013

10131014
type ChatHelper interface {

‎go/libkb/loaduser.go‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,10 @@ func LoadUser(arg LoadUserArg) (ret *User, err error) {
423423
return ret, err
424424
}
425425

426+
cacheUserServiceSummary(m, ret)
426427
} else if !arg.publicKeyOptional {
427428
m.Debug("No active key for user: %s", ret.GetUID())
428-
429-
var emsg string
430-
if arg.self {
431-
emsg = "You don't have a public key; try `keybase pgp select` or `keybase pgp import` if you have a key; or `keybase pgp gen` if you don't"
432-
}
433-
err = NoKeyError{emsg}
429+
return ret, NoKeyError{}
434430
}
435431

436432
return ret, err
@@ -672,3 +668,20 @@ func IsUserByUsernameOffline(m MetaContext, un NormalizedUsername) bool {
672668

673669
return false
674670
}
671+
672+
func cacheUserServiceSummary(mctx MetaContext, user *User) {
673+
serviceMapper := mctx.G().ServiceMapper
674+
if serviceMapper == nil {
675+
// no service summary mapper in current context - e.g. in tests.
676+
return
677+
}
678+
679+
remoteProofs := user.idTable.remoteProofLinks
680+
if remoteProofs != nil {
681+
summary := remoteProofs.toServiceSummary()
682+
err := serviceMapper.InformOfServiceSummary(mctx.Ctx(), mctx.G(), user.id, summary)
683+
if err != nil {
684+
mctx.Debug("cacheUserServiceSummary for %q uid: %q: error: %s", user.name, user.id, err)
685+
}
686+
}
687+
}

‎go/libkb/remote_proof_links.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,16 @@ func (p ProofLinkWithState) ToKeyValuePair() (string, string) {
181181
}
182182

183183
func (p ProofLinkWithState) GetProofType() keybase1.ProofType { return p.link.GetProofType() }
184+
185+
func (r *RemoteProofLinks) toServiceSummary() (ret UserServiceSummary) {
186+
ret = make(UserServiceSummary, len(r.links))
187+
for _, list := range r.links {
188+
if len(list) == 0 {
189+
continue
190+
}
191+
// Get most recent proof for the type
192+
key, val := list[len(list)-1].ToKeyValuePair()
193+
ret[key] = val
194+
}
195+
return ret
196+
}

‎go/protocol/keybase1/user.go‎

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)