openvibers/openvibe.work Commits

Work company pages read their listings through an index (app time 0.24 s) (#166)

OP OpenVibers committed 12 days ago · 0b07123c09 · 2 files, +12 −0

* Work: a company page reads its listings through an index (was ~0.24 s)

* Work: the index test resolves the relation through the test schema's search_path

Changes

ddiff --git a/migrations/0008_company_slug_index.sql b/migrations/0008_company_slug_index.sql
nnew file mode 100644
iindex 0000000..aaae9da
---- /dev/null
++++ b/migrations/0008_company_slug_index.sql
@@@ -0,0 +1,7 @@
++-- phase: expand
++-- A company page filters by the slug computed from the board's spelling (server/jobs/companies.js SLUG_SQL). Without an
++-- index every query folds all ~15k listings: four such scans made /companies/:slug take ~0.24 s. The expression is
++-- immutable, so PostgreSQL can store its value; old code keeps working (it simply does not use the index).
++CREATE INDEX IF NOT EXISTS work_listings_company_slug ON work_listings (
++ (rtrim(left(trim(both '-' from regexp_replace(translate(lower(company), 'äàáâãåāçćčďđëèéêēğïìíîīłñńňöòóôõøōřŕßśšşťţüùúûůūýÿźżžæœ', 'aaaaaaacccddeeeeegiiiiilnnnooooooorrssssttuuuuuuyyzzzao'), '[^a-z0-9]+', '-', 'g')), 80), '-'))
++) WHERE expired = false;
ddiff --git a/test/companies.test.js b/test/companies.test.js
iindex f607aa4..fb345dc 100644
---- a/test/companies.test.js
++++ b/test/companies.test.js
@@@ -36,6 +36,11 @@ const companies = require('../server/jobs/companies');
for (const r of rows) assert.strictEqual(r.slug, companies.slugOf(r.company), r.company);
});
++ await check('the company slug is indexed (0008): a page does not fold every listing', async () => {
++ const [row] = await s.db.many("SELECT to_regclass('work_listings_company_slug') AS idx");
++ assert.strictEqual(String(row.idx), 'work_listings_company_slug');
++ });
++
await check('the index: every company by openings, one entry per slug, the most common spelling; found by name', async () => {
const all = await companies.list(s);
const acme = all.find((c) => c.slug === 'acme-widgets');