jpmcgrath / shortener

Shortener makes it easy to create shortened URLs for your rails application.
MIT License
539 stars 225 forks source link

Let active record format the Time #146

Closed craigmcnamara closed 2 years ago

craigmcnamara commented 2 years ago

Don't pre-format the Time passed to the unexpired scope. This allows the ActiveRecord adapter to format the date according to it's own needs.

Maybe addresses #144 problems, but it seems like they probably have an incorrectly configured application.

Before SQL:

D, [2021-11-30T22:51:27.785105 #91313] DEBUG -- :   Shortener::ShortenedUrl Exists? (0.1ms)  SELECT 1 AS one FROM "shortened_urls" WHERE ("shortened_urls"."expires_at" IS NULL OR "shortened_urls"."expires_at" > '2021-12-01 06:51:27') AND "shortened_urls"."id" = ? LIMIT ?  [["id", 279], ["LIMIT", 1]]
D, [2021-11-30T22:51:27.785193 #91313] DEBUG -- :   ↳ activerecord (6.1.4.1) lib/active_record/log_subscriber.rb:119:in `debug'
D, [2021-11-30T22:51:27.785447 #91313] DEBUG -- :   Shortener::ShortenedUrl Exists? (0.1ms)  SELECT 1 AS one FROM "shortened_urls" WHERE ("shortened_urls"."expires_at" IS NULL OR "shortened_urls"."expires_at" > '2021-12-01 06:51:27') AND "shortened_urls"."id" = ? LIMIT ?  [["id", 278], ["LIMIT", 1]]
D, [2021-11-30T22:51:27.785537 #91313] DEBUG -- :   ↳ activerecord (6.1.4.1) lib/active_record/log_subscriber.rb:119:in `debug'
D, [2021-11-30T22:51:27.785770 #91313] DEBUG -- :   Shortener::ShortenedUrl Exists? (0.0ms)  SELECT 1 AS one FROM "shortened_urls" WHERE ("shortened_urls"."expires_at" IS NULL OR "shortened_urls"."expires_at" > '2021-12-01 06:51:27') AND "shortened_urls"."id" = ? LIMIT ?  [["id", 277], ["LIMIT", 1]]
D, [2021-11-30T22:51:27.785859 #91313] DEBUG -- :   ↳ activerecord (6.1.4.1) lib/active_record/log_subscriber.rb:119:in `debug'
D, [2021-11-30T22:51:27.786130 #91313] DEBUG -- :   Shortener::ShortenedUrl Load (0.2ms)  SELECT "shortened_urls".* FROM "shortened_urls" WHERE ("shortened_urls"."expires_at" IS NULL OR "shortened_urls"."expires_at" > '2021-12-01 06:51:27')

After SQL:

D, [2021-11-30T22:51:55.141241 #91931] DEBUG -- :   Shortener::ShortenedUrl Exists? (0.1ms)  SELECT 1 AS one FROM "shortened_urls" WHERE ("shortened_urls"."expires_at" IS NULL OR "shortened_urls"."expires_at" > '2021-12-01 06:51:55.136749') AND "shortened_urls"."id" = ? LIMIT ?  [["id", 285], ["LIMIT", 1]]
D, [2021-11-30T22:51:55.141333 #91931] DEBUG -- :   ↳ activerecord (6.1.4.1) lib/active_record/log_subscriber.rb:119:in `debug'
D, [2021-11-30T22:51:55.141578 #91931] DEBUG -- :   Shortener::ShortenedUrl Exists? (0.0ms)  SELECT 1 AS one FROM "shortened_urls" WHERE ("shortened_urls"."expires_at" IS NULL OR "shortened_urls"."expires_at" > '2021-12-01 06:51:55.136749') AND "shortened_urls"."id" = ? LIMIT ?  [["id", 284], ["LIMIT", 1]]
D, [2021-11-30T22:51:55.141661 #91931] DEBUG -- :   ↳ activerecord (6.1.4.1) lib/active_record/log_subscriber.rb:119:in `debug'
D, [2021-11-30T22:51:55.141889 #91931] DEBUG -- :   Shortener::ShortenedUrl Exists? (0.0ms)  SELECT 1 AS one FROM "shortened_urls" WHERE ("shortened_urls"."expires_at" IS NULL OR "shortened_urls"."expires_at" > '2021-12-01 06:51:55.136749') AND "shortened_urls"."id" = ? LIMIT ?  [["id", 283], ["LIMIT", 1]]
D, [2021-11-30T22:51:55.141977 #91931] DEBUG -- :   ↳ activerecord (6.1.4.1) lib/active_record/log_subscriber.rb:119:in `debug'
D, [2021-11-30T22:51:55.142271 #91931] DEBUG -- :   Shortener::ShortenedUrl Load (0.2ms)  SELECT "shortened_urls".* FROM "shortened_urls" WHERE ("shortened_urls"."expires_at" IS NULL OR "shortened_urls"."expires_at" > '2021-12-01 06:51:55.136749')
craigmcnamara commented 2 years ago

@fschwahn @jpmcgrath Hey, I submitted some patches a while back. I was just dropping in to check on the state of things because I'm probably installing Shortener in my latest app tomorrow. I responded to some pull requests, I hope I'm not over stepping. Things are looking great still. Thanks for the hard work.

fschwahn commented 2 years ago

It seems CI is broken due to https://travis-ci.org/ being abandoned in favor of https://www.travis-ci.com/. @jpmcgrath I think that's something only you can fix.

fschwahn commented 2 years ago

@craigmcnamara I want ahead and integrated github actions. Can you rebase the PR?

fschwahn commented 2 years ago

@jpmcgrath could you maybe release a new version? This is causing deprecation warnings on rails 7.

jpmcgrath commented 2 years ago

Yes, I can release a new version soon. Thanks for the prompt.