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

Conversation

byucesoy
Copy link
Member

@byucesoy byucesoy commented May 4, 2024

While working on DeletedRecord, we frequently need to find the record from its ubid. This commit adds a helper method for that.

@byucesoy byucesoy requested a review from a team May 4, 2024 00:45
@byucesoy byucesoy self-assigned this May 4, 2024
While working on DeletedRecord, we frequently need to find the record from its
ubid. This commit adds a helper method for that.
@byucesoy byucesoy force-pushed the add-deleted-record-helper branch from 4e3c633 to 17f0af1 Compare May 4, 2024 03:00
Comment on lines 19 to +24
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
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

@@ -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.

@@ -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
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants