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

kv: Add increment functionality #45

Merged
merged 36 commits into from Aug 26, 2019
Merged

kv: Add increment functionality #45

merged 36 commits into from Aug 26, 2019

Conversation

@fletchto99
Copy link
Member

@fletchto99 fletchto99 commented Aug 1, 2019

For some functionality we're requiring the ability to increment the values of specific keys. This PR adds the ability to increment a key within KV returning the new value. For example:

GitHub.kv.set("foo", "1")
GitHub.kv.increment("foo")
#=> 2

By default increment will increment the value by 1 however you can pass an amount: parameter to specifiy the amount. Furthermore, incrementing can also take an expires parameter to update the TTL.

Todo:

  • Handle values which are non-integer in type

/cc @mastahyeti
/cc @dbussink Since you had the idea for the original last_insert_id hack :)

lib/github/kv.rb Outdated Show resolved Hide resolved
lib/github/kv.rb Outdated Show resolved Hide resolved
Copy link
Member Author

@fletchto99 fletchto99 left a comment

I think this should be good for an initial pass of feedback.

lib/github/kv.rb Outdated Show resolved Hide resolved
@fletchto99 fletchto99 marked this pull request as ready for review Aug 2, 2019
@fletchto99 fletchto99 requested a review from btoews Aug 2, 2019
lib/github/kv.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@btoews btoews left a comment

Looking good. This code could use a bunch of comments though, especially given the nuanced MySQL behavior it relies on.

lib/github/kv.rb Outdated Show resolved Hide resolved
test/github/kv_test.rb Show resolved Hide resolved
lib/github/kv.rb Outdated Show resolved Hide resolved
test/github/kv_test.rb Show resolved Hide resolved
fletchto99 added 3 commits Aug 6, 2019
@fletchto99
Copy link
Member Author

@fletchto99 fletchto99 commented Aug 6, 2019

This code could use a bunch of comments though

Good idea. I've added some comments in 1a5789b - feel free to let me know if it's too much or too little.

@btoews
btoews approved these changes Aug 6, 2019
Copy link
Contributor

@btoews btoews left a comment

Looks good. Thanks for explaining things.

lib/github/kv.rb Outdated Show resolved Hide resolved
lib/github/kv.rb Outdated Show resolved Hide resolved
lib/github/kv.rb Outdated Show resolved Hide resolved
@btoews
Copy link
Contributor

@btoews btoews commented Aug 6, 2019

/cc @zerowidth Would you be able to review this?

fletchto99 added 15 commits Aug 6, 2019
This reverts commit 54dd97f.
fletchto99 added 7 commits Aug 14, 2019
lib/github/kv.rb Outdated Show resolved Hide resolved
lib/github/kv.rb Show resolved Hide resolved
lib/github/kv.rb Outdated Show resolved Hide resolved
test/github/kv_test.rb Show resolved Hide resolved
@btoews
btoews approved these changes Aug 19, 2019
Copy link
Contributor

@btoews btoews left a comment

I'm really happy with how this has turned out. Thanks for bearing with me and explaining everything multiple times.

lib/github/kv.rb Outdated Show resolved Hide resolved
fletchto99 added 5 commits Aug 19, 2019
@fletchto99
Copy link
Member Author

@fletchto99 fletchto99 commented Aug 20, 2019

Turns out my CLIENT_FOUND_ROWS logic broke things since we use a different adapter (thus looking up the flags on the raw_connection failed). However we don't actually need to check that at all. Instead we can just do:

sql.affected_rows == 0 || (sql.affected_rows == 1 && sql.last_insert_id == 0)

as seen in ee36818. This will handle any adapter backing active record as well as both CLIENT_FOUND_ROWS being set or not set.

Copy link
Member

@zerowidth zerowidth left a comment

🤘

zerowidth added 2 commits Aug 26, 2019
@zerowidth zerowidth merged commit 9a8fcf8 into master Aug 26, 2019
@zerowidth zerowidth deleted the fletchto99/kv-increment branch Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.