fix: add url_hash column for cross-scraper lead deduplication#20
Open
DeryFerd wants to merge 1 commit into
Open
fix: add url_hash column for cross-scraper lead deduplication#20DeryFerd wants to merge 1 commit into
DeryFerd wants to merge 1 commit into
Conversation
6c7c90d to
cc62af2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the problem?
Right now, lead deduplication only works within a single scraper. Each scraper computes a
job_idby hashing the URL in its own way — scout.py useshashlib.md5(url)[:16], free_scout.py useslead_id(platform, url), x_scout.py uses a different hash. They all check url_exists(jid) before saving, but since thejidis derived differently per scraper, the same job posting from two different sources gets saved as two separate leads.This means the leads table accumulates duplicates — same job URL, different
job_ids, no way to detect them.What this PR does
Adds a
url_hashcolumn to the leads table that stores a normalized hash of the URL, independent of which scraper found it. This makes cross-scraper dedup possible: any scraper can call url_exists_by_url(url) to check if a lead with that URL already exists, regardless of who saved it.URL normalization in _url_hash():
/posting/→/posting)#sectionremoved)HTTPS://Jobs.Example.COM→https://jobs.example.com)?b=2&a=1→?a=1&b=2)Files changed:
url_hash TEXT DEFAULT ''column (auto-migration). New _url_hash(url) function with the normalization logic above. New url_exists_by_url(url) that queries byurl_hash. save_lead() now stores _url_hash(u) on INSERT. New backfill_url_hashes() helper to populate the column for existing leads.How to use
Scrapers can now add a url_exists_by_url(url) check before saving, which will catch duplicates even when the
job_iddiffers. The existing url_exists(jid) check still works as before for same-scraper dedup.For existing databases, run backfill_url_hashes() once to populate the new column.