DEV: First pass improving topic tracking state (PR #12555)

GitHub

I mainly wanted this to be in the cloud™ not just my PC

BTW you can push branches to origin without a PR and it will do this!

I mainly wanted this to be in the cloud™ not just my PC

BTW you can push branches to origin without a PR and it will do this!

Yeah I know, I mainly find opening a PR helps me see the whole overview of the changes I’ve made — I really like GitHub’s diff interface for the files :slight_smile:

tags,tag_ids = post.topic.tags.pluck(:id, :name).transpose

not happy with uniq being called unconditionally. In fact maybe part of the contract shall be … refiner shall not introduce dupes … then you don’t need this at all.

got to do this “after” as well so you do not leak state

Hmm in that case I probably need to pass some data structure class to the refine method instead of the raw array, then that can control this e.g.

class TopicTrackingStateReport do
  def initialize(report_data)
    @report_data = report_data
    @report_data_map = {}
    @report_data.each do |data|
      if !@report_data_map.key?(data[:topic_id])
        @report_data_map[data[:topic_id]] = data
      end
    end
  end

  def add(data)
    if @report_data_map.key?(data.topic_id) raise NotUniqueError
    @report_data_map[data.topic_id] = data
  end

  def read
    @report_data
  end
end

I think I should turn the data array into a hash to speed up the lookups. This way refinement.call would pass through an instance of this class. Thoughts? I don’t think we want to trust the refiner methods to not introduce dupes

A simple compromise would be not to call uniq unless a refinement happened, I think that is probably the easiest way to go here.