00:00:13.719
director at Sky matters and he's from
00:00:15.839
Hong
00:00:18.560
Kong thank
00:00:21.960
you okay uh hello everyone uh my name is
00:00:25.800
Jack today I'm going to talk about grow
00:00:28.039
from small simple steps so learning from
00:00:30.920
Amazon the name can be shorter gr from
00:00:34.040
S3 uh yeah today I'm going to walk you
00:00:37.120
through one of my pel experience
00:00:39.520
contributing to a open source project um
00:00:42.760
which was not going really well
00:00:44.960
surprisingly uh the problem is like this
00:00:47.320
the library name is called active record
00:00:49.399
import so how does it work once you need
00:00:52.719
for example import 10 books records into
00:00:55.680
a database at the same time right
00:00:58.000
instead of writing 10 different SQL
00:01:01.039
statement and 10 different uh 10
00:01:04.080
database connections you can write one
00:01:06.680
and just say book do import books and
00:01:09.360
then all the data all the record insert
00:01:11.400
in the database right uh so it helps a
00:01:13.799
lot if we need to insert millions of
00:01:15.680
data at the same
00:01:17.280
time uh yeah and but now uh some problem
00:01:21.720
comes once we use enom in rails so enum
00:01:25.439
is a feature since I think rails
00:01:28.479
4.1 um basically you can Define the inam
00:01:31.600
attributes with some uh for example the
00:01:33.840
status here must be either drafted
00:01:36.280
finished or published uh but somehow the
00:01:39.320
value save in a database uh is always
00:01:42.159
integer so so default so by so drafted
00:01:46.040
is zero finished is one and published is
00:01:50.119
two uh however to you to do the
00:01:52.600
assignment you can say uh do status
00:01:56.680
equal to zero or do status equal to jaft
00:02:00.320
uh yeah only integer is saved um
00:02:02.960
sometimes in the migration you need to
00:02:04.920
have you you want to have like default
00:02:07.039
value uh to the Staters but once we use
00:02:10.879
that again boom as argument error says
00:02:14.920
integer zero is not a valid so my first
00:02:19.560
question is um looks like I'm not I'm
00:02:22.840
not sure why the integer zero is used
00:02:25.160
instead of so why the string is used
00:02:28.239
instead of the integer then I look at uh
00:02:31.680
how does it work in the pryle because I
00:02:34.080
was using prle and find out there's a
00:02:37.160
method called PG uh get x p expr and
00:02:41.840
this is the method to get the default
00:02:43.560
value uh and the output is actually a
00:02:46.080
string so that's why we get string zero
00:02:48.159
instead of the integer and then I think
00:02:50.440
rails must be small enough to do the
00:02:53.000
type casting and we can always assign uh
00:02:56.080
integer attributes with uh string and it
00:02:59.800
it should be automatically do the
00:03:01.360
conversion um but somehow in the in the
00:03:03.840
input methods in the library uh it it
00:03:06.879
just use read attributes before type
00:03:09.120
casting uh so it basically just read
00:03:11.480
attributes from the instance without
00:03:13.280
doing any type casting uh and then uh
00:03:16.040
the place the place uh raise error is
00:03:19.720
the the the one we call method s k
00:03:22.720
equals to
00:03:23.879
V uh yeah and this is place because zero
00:03:26.840
is not a predefined uh string
00:03:30.280
and uh yeah so so there's error um and I
00:03:34.760
was also asking why the test all the
00:03:37.040
tests got to P if you still take care
00:03:39.920
about still think care of test so this
00:03:41.959
is a model file inside the spec uh it
00:03:44.959
basically defines the enum sters once
00:03:46.959
the active record version is larger than
00:03:50.760
4.1 uh for active record version 31 32 4
00:03:55.079
41 and 42 does anyone find the problem
00:03:58.040
what's wrong here
00:04:02.680
yeah the 2i because for 2i at the most
00:04:06.760
it converts the version to 4 point just
00:04:09.560
convert to four and the value is never
00:04:11.799
larger than 4.1 so the enum attribute is
00:04:15.000
never
00:04:16.160
defined okay so I get the problem I know
00:04:18.919
what's wrong I got the fail test case
00:04:21.359
now i r roll up my slaves okay work hard
00:04:25.919
overnight and then I received a lot of
00:04:29.160
encourage
00:04:30.520
ment and at the
00:04:33.800
end okay sorry I go
00:04:37.639
back I'll go back sorry
00:04:43.280
little ah so wait a second
00:04:48.560
so so yeah uh and and I reive a lot of
00:04:53.919
uh encouragement and and at last the the
00:04:57.560
author of the repo and it says it is a
00:04:59.600
best pro request I have ever seen
00:05:02.360
awesome but it didn't happen at all so
00:05:06.240
the the reality is okay the reality is I
00:05:10.560
sat down and was not sure what was wrong
00:05:13.880
the first I thought okay it might be a
00:05:16.360
problem with postr SLE but it turns out
00:05:18.960
okay s lights and myl are the same and
00:05:22.880
then I think okay that might be a
00:05:24.720
problem because rails I think rails must
00:05:26.960
be smarter than this but maybe way way
00:05:30.160
because enum it accepts strings like
00:05:32.680
draft and it never should be convert
00:05:36.400
that the string to to integer
00:05:38.720
automatically and At Last I Define okay
00:05:41.680
I I I want have a full request to
00:05:43.479
replace uh read attributes before type
00:05:45.960
cast with read attributes which
00:05:48.080
basically uh do the type casting and
00:05:51.000
then the first maintainer comes here say
00:05:54.000
okay why do uh why uh in our library
00:05:57.280
read attributes before typ casting is
00:05:59.120
used H I'm a bit confused because I
00:06:02.120
thought this is a question I should ask
00:06:04.319
him and he should told me
00:06:07.720
right uh I was bit confused and then
00:06:10.520
here comes another uh and here comes
00:06:12.880
another commuters he said oh actually
00:06:15.199
the code was back to 2007 and but but go
00:06:19.479
ahead go go to use real uh read
00:06:21.720
attributes if that got test case pass
00:06:24.240
really 2007 you know that was rails
00:06:27.759
1.2 uh I got really sad about this and
00:06:31.199
then here this comes another uh the
00:06:34.720
first commuter actually come back and
00:06:36.919
say okay actually the type cting is
00:06:39.759
handling somewhere else but uh but go
00:06:42.840
ahead to to use read attributes and I
00:06:44.960
was even confused because it's not
00:06:46.840
logical at all if there the type casting
00:06:49.120
is handled somewhere else why need to
00:06:50.960
use read attributes to do the type
00:06:53.199
casting
00:06:55.039
duplicated uh confused confused and then
00:06:58.599
uh I tell them okay okay read attributes
00:07:00.599
is actually slower for the type casting
00:07:02.319
50 times slower um because I think my
00:07:05.479
Pro request was actually not that
00:07:08.319
good uh when I was still thinking there
00:07:10.599
was another commuter actually comes uh
00:07:13.080
in in another Pool request actually made
00:07:15.360
a very simple fix and kind of get all
00:07:17.560
the Tex pass and he just basically
00:07:20.080
changed the model doent k equals V with
00:07:23.960
model square bracket k equal V uh I
00:07:26.960
thought these two are the same but
00:07:28.680
somehow there are
00:07:30.560
not uh because the square bracket equal
00:07:33.639
sign basically is uh the same with
00:07:37.360
rights underscore attributes and which
00:07:39.840
does type cussing as well I'm thinking
00:07:42.919
okay it's it's it's working but not not
00:07:45.400
very good either uh but at the moment
00:07:47.759
when everyone is was stucked uh the the
00:07:51.479
Comm the maintainer say Okay I I want to
00:07:53.960
close this I want to merge your pro
00:07:55.479
request uh go ahead but I'm going to
00:07:57.680
create another Pro request and emerge
00:07:59.919
the changes of of both of your your your
00:08:02.759
PO requests so this is uh yeah this is
00:08:07.319
kind of the the story and through the
00:08:09.560
entire story I had no much like positive
00:08:14.280
emotions uh and and the the result was
00:08:17.080
not very good my although my PO request
00:08:19.599
got merged uh but I don't have much code
00:08:22.680
contributed uh but even this I get some
00:08:25.520
takeaways and the takeaways is really
00:08:27.720
something I'm going to talk about today
00:08:29.479
so the first I know much more about the
00:08:32.000
active record connection adapter it is
00:08:34.880
good design to support your uh
00:08:37.919
application support multiple database
00:08:40.279
types and which is scalable and second I
00:08:43.599
understand more about different types of
00:08:45.040
assignment in active record and type
00:08:47.440
casting and also understand how at least
00:08:50.560
default value Works in postra sqle and
00:08:54.120
the library itself is actually pretty
00:08:55.600
good the people amazing this is a good
00:08:57.839
example uh or libr liate to uh as a
00:09:00.800
showcase how to support multiple ruby
00:09:03.120
versions and database adapters at the
00:09:05.240
same time and of course no uh reals you
00:09:08.600
know more and and here's what are
00:09:10.680
takeaways I come here to for you so the
00:09:13.560
first don't believe in Stars so for this
00:09:15.920
Library it has more
00:09:17.839
than so for this Library it has more
00:09:20.240
than 1,500 stars and it is updated very
00:09:23.399
frequently but even for this there was
00:09:25.760
still some mistakes um I think most of
00:09:28.399
the beginners can
00:09:29.959
fix and then uh sorry second don't think
00:09:33.160
of making a p a perfect pool request at
00:09:35.480
the first so learn from the
00:09:37.240
conversations from others uh and last I
00:09:40.399
think contributing to open source
00:09:42.240
project uh sometime is Trivial like
00:09:45.360
small simple steps but sometimes even
00:09:48.000
the small simple steps is not that easy
00:09:50.839
is sometimes not
00:09:52.399
smooth sometimes the reality is like
00:09:55.640
this so my so so my first my my sorry my
00:09:59.360
last suggestion is like go ahead don't
00:10:02.120
compromise thank
00:10:06.640
you