Skip to content

Exotic values in subscription query vectors break sorting due to sorted-map #86

@lassemaatta

Description

@lassemaatta

The sorting of subscriptions in the "Active subscriptions" window work fine when all the query vectors are simple, e.g. [:foobar/subscription :foo "bar" 123]. But sorting is automatically disabled if any of the query vectors contain anything even a bit more exotic, such as maps, functions etc as sorted-map has trouble comparing them. This is unfortunate; as the number of active subscriptions increases, so does the value of sorting. But this also increases the risk that somewhere within the subscriptions there's query vector that breaks the sorting.

If the sorting cannot handle arbitrary complex query vectors, would it be possible to at least fallback to sorting just by the subscription name, ie. the first element of the query vector? Alternatively, perhaps re-frisk could use sorted-map-by, e.g. something like

(defn- safe-compare
  [a b]
  (try
    (compare a b)
    (catch :default e
     1)))

(defn sort-map [value checkbox-val checkbox]
  (if (and checkbox-val (map? value))
    (try
      (into (sorted-map-by safe-compare) value)
      (catch :default e
        (do
          (reset! checkbox false)
          value)))
    value))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions