open-company / open-company-web

OpenCompany Web Application - Carrot web UI
https://github.com/open-company
Other
61 stars 9 forks source link

Fix search error #1144

Closed bago2k4 closed 4 years ago

bago2k4 commented 4 years ago

Sentry: https://sentry.io/organizations/opencompany/issues/1551455336/?project=74293&referrer=slack

This error is due to some results not having the board-slug set in the :_source map. This is a workaround: it tries to use the board-uuid if present and if the client knows which board is that and discards all results w/o a board-slug after this.

The ideal would be to load all the records in ES w/o a board-slug and re-index them.

To test (try to simulate a result w/o board-slug):

Replace line oc.web.stores.search/cleanup-results (line 50) with:

(defn- cleanup-results
  "Entries have the uuid in this format: entry-0000-0000-0000-0000
   replace those with only the UUID and make sure they have a board-slug,
   if the slug is missing replace it with the board-uuid.
   Finally filter out all the results that still don't have a board-slug."
  [results]
  (let [results (vec (for [i (range (count results))]
                        (cond
                          (= i 0)
                          (assoc (get results i) :board-slug nil)
                          (= i 1)
                          (-> (get results i)
                           (assoc :board-slug nil)
                           (assoc :board-uuid "1234-1234-1234")
                         :else
                         (get results i)))))]
  (->> results
   (mapv cleanup-result)
   (filterv #(-> % :_source :board-slug seq)))))