ostark / upper

Integrates Edge Caches like Fastly, KeyCDN, Cloudflare and Varnish with Craft.
MIT License
102 stars 22 forks source link

adds uid_urlhash_idx on installation to support #42

Closed markhuot closed 3 years ago

markhuot commented 3 years ago

without this Postgres will complain that "ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification" with the following SQL,

INSERT INTO "upper_cache" ("urlHash", "url", "tags", "headers", "siteId", "dateCreated", "dateUpdated", "uid") VALUES ($1, $2, ARRAY[]::varchar[], $3, $4, $5, $6, $7) ON CONFLICT ("uid", "urlHash") DO UPDATE SET "urlHash"=$8, "url"=$9, "tags"=ARRAY[]::varchar[], "headers"=$10, "siteId"=$11, "dateCreated"=$12, "dateUpdated"=$13, "uid"=$14

Probably would need an additional migration for existing installations. If this makes sense I can make that migration before this merges.

timkelty commented 3 years ago

@markhuot @ostark

So this got rid of the ON CONFLICT error, but replaced it with this:

sql_error_code = 23505 ERROR:  duplicate key value violates unique constraint "urlhash_idx"
sql_error_code = 23505 DETAIL:  Key ("urlHash")=(1ac88b98ff26828f9061fc9ac11d93d0) already exists.
sql_error_code = 23505 STATEMENT:  INSERT INTO "upper_cache" ("urlHash", "url", "tags", "headers", "siteId", "dateCreated", "dateUpdated", "uid") VALUES ($1, $2, ARRAY[]::varchar[], $3, $4, $5, $6, $7) ON CONFLICT ("uid", "urlHash") DO UPDATE SET "urlHash"=$8, "url"=$9, "tags"=ARRAY[]::varchar[], "headers"=$10, "siteId"=$11, "dateCreated"=$12, "dateUpdated"=$13, "uid"=$14

Likely related: https://github.com/yiisoft/db-pgsql/issues/6

markhuot commented 3 years ago

Unfortunately, I believe that's expected for Postgres. I'd need to check it out, but I think Postgres reports that any time you do an ON CONFLICT…DO UPDATE query. Maybe there's a way to silent that notice?

timkelty commented 3 years ago

Worth noting that for many cases, simply setting useLocalTags to false takes any DB issues out of the equation. I'm thinking we should maybe adjust that default dependent on the active driver? Eg, if Fastly (as it has tag invalidation), the default should be false.