Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper method for decoding deleted record #1547

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/pry
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ require_relative "../loader"

require "pry"

Sequel.extension :pg_json_ops

def dev_project
return unless Config.development?
ac = Account[email: "[email protected]"] || Account.create_with_id(email: "[email protected]")
Expand All @@ -17,6 +19,10 @@ def udec(*)
UBID.decode(*)
end

def udec_deleted(ubid)
DeletedRecord.where(Sequel.pg_json(:model_values)["name"] => Sequel.pg_jsonb_wrap(UBID.parse(ubid).to_uuid)).first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we must add a gin index for this field. Simply querying deleted records in production is almost unbearable at this point.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also using almost all our space. Should we consider partitioning as well? How often are we digging in the ancient past? Not often, right?

GIN is perhaps the first thing to try, though the idea of a GIN over all (ever growing) history that has to get updated with every deletion makes me a little bit suspenseful. Just a bit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we filter by id instead of name?

Suggested change
DeletedRecord.where(Sequel.pg_json(:model_values)["name"] => Sequel.pg_jsonb_wrap(UBID.parse(ubid).to_uuid)).first
DeletedRecord.where(Sequel.pg_json(:model_values)["id"] => Sequel.pg_jsonb_wrap(UBID.parse(ubid).to_uuid)).first

end
Comment on lines 19 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding it to the udec as a second option?
Probably we will run udec first and it will return nil, then we will run udec_deleted

Suggested change
UBID.decode(*)
end
def udec_deleted(ubid)
DeletedRecord.where(Sequel.pg_json(:model_values)["name"] => Sequel.pg_jsonb_wrap(UBID.parse(ubid).to_uuid)).first
end
UBID.decode(*) || DeletedRecord.where(Sequel.pg_json(:model_values)["name"] => Sequel.pg_jsonb_wrap(UBID.parse(ubid).to_uuid)).first
end


opts = Pry::CLI.parse_options
Pry.config.prompt_name = if Config.production?
"\e[41m⚠️ %s\e[0m" % "clover-#{Config.rack_env}"
Expand Down