Skip to content

Commit

Permalink
Merge pull request #199 from pixlise/feature/user-icon-caching
Browse files Browse the repository at this point in the history
Stops returning user icon with ownership summary
  • Loading branch information
RyanStonebraker authored Mar 26, 2024
2 parents 76c8803 + ec464d5 commit 25ffc30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion api/ws/wsHelpers/ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func ListGroupAccessibleIDs(requireEdit bool, objectType protos.ObjectType, grou
return result, nil
}

func MakeOwnerSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ts timestamper.ITimeStamper) *protos.OwnershipSummary {
func FetchOwnershipSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ts timestamper.ITimeStamper, fullDetails bool) *protos.OwnershipSummary {
user, err := getUserInfo(ownership.CreatorUserId, db, ts)
result := &protos.OwnershipSummary{
CreatedUnixSec: ownership.CreatedUnixSec,
Expand Down Expand Up @@ -237,9 +237,23 @@ func MakeOwnerSummary(ownership *protos.OwnershipItem, sessionUser SessionUser,
}

result.SharedWithOthers = result.ViewerUserCount > 0 || result.ViewerGroupCount > 0 || result.EditorUserCount > 0 || result.EditorGroupCount > 0

// Hide more data intensive fields if we don't care
if !fullDetails {
result.CreatorUser.IconURL = ""
}

return result
}

func MakeOwnerSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ts timestamper.ITimeStamper) *protos.OwnershipSummary {
return FetchOwnershipSummary(ownership, sessionUser, db, ts, false)
}

func MakeFullOwnerSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ts timestamper.ITimeStamper) *protos.OwnershipSummary {
return FetchOwnershipSummary(ownership, sessionUser, db, ts, true)
}

func FindUserIdsFor(objectId string, mongoDB *mongo.Database) ([]string, error) {
filter := bson.M{"_id": objectId}
opts := options.FindOne()
Expand Down
8 changes: 8 additions & 0 deletions api/ws/wsHelpers/userDBCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import (
)

func GetDBUser(userId string, db *mongo.Database) (*protos.UserDBItem, error) {
// opts := options.FindOne().SetProjection(bson.D{
// {Key: "_id", Value: true},
// {Key: "info.id", Value: true},
// {Key: "info.name", Value: true},
// {Key: "info.email", Value: true},
// {Key: "datacollectionversion", Value: true},
// {Key: "notificationsettings", Value: true},
// })
userResult := db.Collection(dbCollections.UsersName).FindOne(context.TODO(), bson.M{"_id": userId})
if userResult.Err() != nil {
return nil, userResult.Err()
Expand Down

0 comments on commit 25ffc30

Please sign in to comment.