Postgres saves the day
- kith: i have a database with _lots_ of ip addresses
- kith: and when i search for IPs i'm selecting all of them then run IPAddr.new on them and check if its a net which my ip belongs to
- injekt: kith: More than 23k?
- kith: injekt: dunno
- kith: anyways, the script is friggin slow
- injekt: I'd imagine so
- injekt: er, 'I can imagine'
- kith: would it be smart to kinda write some stored procedure to resolv ip addressing beforehand?
- bleything: kith: do you want to validate the ip every time, or just once? because you could do it on the way in instead of the way out.
- kith: bleything: what do you mean by way in/out? and well yeah it has to be validated everytime someone is looking for an ip address
- vovcia: kith: WHERE ip LIKE '12.34%'
- injekt: kith: He means when you throw an IP address in the db, can't you just do all your validations there
- bleything: kith: I meant, yes, if you're going to iterate over a db and create a new object for an item in every row, it's going to be slow. if you could check them at insert time it'd be easier, but it's not clear what you're doing.
- evan: if you're looking for a particular byte pattern.
- kith: vovcia: not gonna work
- bougyman: some databases have a cidr column type, so they take care of it at the column/db level.
- bougyman: kith: are you using postgres?
- bougyman: kith: yes.
- bougyman: you can do subnet lookups and all sorts of cool stuff with it.
- kith: does pg have this?
- bougyman: yes
- kith: FUUUCK :D
- vovcia: bougyman: ipv6 as well?
- kith: bougyman: why didnt you tell me earlier?
- bougyman: http://www.postgresql.org/docs/8.3/static/datatype-net-types.html\
- bougyman: -\
- bougyman: cidr7 or 19 bytes IPv4 and IPv6 networks
- bougyman: inet 7 or 19 bytes IPv4 and IPv6 hosts and networks
- bougyman: macaddr 6 bytes MAC addresses
- bougyman: woops
- bougyman: kith: select inet '192.168.1.5' << inet '192.168.1/24' as contained;
- bougyman: that's the kind of sweet stuff you get (is 192.168.1.5 in 192.168.1.0/24?)
- kith: fuck need to read up on that
- bougyman: http://www.postgresql.org/docs/8.3/static/functions-net.html
- bougyman: there ya go
- kith: bougyman: thx man
- bleything: that is extra rad.
- kith: rad?
- bleything: awesome. cool. neat.
Short URL for this post: http://tmblr.co/ZPG7SySwulk