Just a quick POC to move fast :P

We use a search pointer to keep track of
the next row to inesrt to. For every new search
we increment the pointer and do modulo 5.
This means that the value will always remain
between 0-4. And that way, we will always overwrite
the oldest entry on every search.

And while getting the results, we get
all results for that user.

The search parameters are json marshalled
and stored as a JSON blob. This is because
there is no need to search/filter them
in the DB.

Pending items:
Tests obviously.

To improve:
The client needs to send the channel ids
instead of channel names.
Этот коммит содержится в:
Agniva De Sarker
2022-05-16 13:16:11 +05:30
коммит произвёл GitHub
родитель 979b616189
Коммит aa59c28b04
26 изменённых файлов: 488 добавлений и 68 удалений

Просмотреть файл

@@ -92,6 +92,7 @@ func (api *API) InitUser() {
api.BaseRoutes.User.Handle("/uploads", api.APISessionRequired(getUploadsForUser)).Methods("GET")
api.BaseRoutes.User.Handle("/channel_members", api.APISessionRequired(getChannelMembersForUser)).Methods("GET")
api.BaseRoutes.User.Handle("/recent_searches", api.APISessionRequiredDisableWhenBusy(getRecentSearches)).Methods("GET")
api.BaseRoutes.Users.Handle("/invalid_emails", api.APISessionRequired(getUsersWithInvalidEmails)).Methods("GET")
@@ -3245,3 +3246,25 @@ func getUsersWithInvalidEmails(c *Context, w http.ResponseWriter, r *http.Reques
b, _ := json.Marshal(users)
w.Write(b)
}
func getRecentSearches(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireUserId()
if c.Err != nil {
return
}
if !c.App.SessionHasPermissionToUser(*c.AppContext.Session(), c.Params.UserId) {
c.SetPermissionError(model.PermissionEditOtherUsers)
return
}
searchParams, err := c.App.GetRecentSearchesForUser(c.Params.UserId)
if err != nil {
c.Err = err
return
}
if err := json.NewEncoder(w).Encode(searchParams); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
}
}