« Back to channel list

#elixir-lang - 08 July 2019

« Back 1 day Forward 1 day »
[00:00:25] atk: has joined #elixir-lang
[00:11:06] orbyt_: has joined #elixir-lang
[00:14:06] averell: has joined #elixir-lang
[00:27:00] foggyboi: has joined #elixir-lang
[00:59:49] jeffro_: has joined #elixir-lang
[01:11:21] jeffweiss: has joined #elixir-lang
[01:13:18] tomterl: has joined #elixir-lang
[01:29:24] notzmv: has joined #elixir-lang
[01:40:39] duane: has joined #elixir-lang
[01:54:37] jeffro_: has joined #elixir-lang
[02:10:24] kriwil: has joined #elixir-lang
[02:10:31] Saukk: has joined #elixir-lang
[02:19:04] ariedler: has joined #elixir-lang
[02:44:53] jeffweiss: has joined #elixir-lang
[02:46:47] Sgeo_: has joined #elixir-lang
[03:08:01] jeffweiss: has joined #elixir-lang
[03:16:18] jeffweiss: has joined #elixir-lang
[03:24:42] lanodan: has joined #elixir-lang
[03:26:02] samrose: has joined #elixir-lang
[03:27:17] lao-tzu: has joined #elixir-lang
[03:45:25] jeffro_: has joined #elixir-lang
[03:49:19] pupoxcu: has joined #elixir-lang
[03:49:34] mdbm: has joined #elixir-lang
[04:13:04] mdbm_: has joined #elixir-lang
[04:13:43] Sgeo_: has joined #elixir-lang
[04:14:38] mdbm_: serafeim, good morning
[04:18:20] wsieroci: has joined #elixir-lang
[04:20:32] ariedler: has joined #elixir-lang
[04:45:25] ephemera_: has joined #elixir-lang
[05:00:35] ephemera_: has joined #elixir-lang
[05:03:34] DTZUZO: has joined #elixir-lang
[05:03:38] za1b1tsu: has joined #elixir-lang
[05:17:22] lessless: has joined #elixir-lang
[05:25:16] za1b1tsu: has joined #elixir-lang
[05:36:19] serafeim: good morning
[05:58:09] voltone: has joined #elixir-lang
[06:01:34] gvaughn: has joined #elixir-lang
[06:01:50] jeffweiss: has joined #elixir-lang
[06:02:12] infowolfe: has joined #elixir-lang
[06:02:12] infowolfe: has joined #elixir-lang
[06:07:22] foggyboi: has joined #elixir-lang
[06:21:13] ariedler: has joined #elixir-lang
[06:32:14] celyr: has joined #elixir-lang
[06:33:57] za1b1tsu: has joined #elixir-lang
[06:45:54] jeffro_: has joined #elixir-lang
[06:54:19] tuacker: has joined #elixir-lang
[07:02:36] purebadger: has joined #elixir-lang
[07:05:59] voltone: has joined #elixir-lang
[07:10:16] mdbm_: has joined #elixir-lang
[07:11:57] sangoma: has joined #elixir-lang
[07:19:01] DTZUZO: has joined #elixir-lang
[07:27:18] serafeim: i'm going to upgrade my project to elixir 1.9; have you experienced any problems / pain points with this upgrade ?
[07:30:27] gvaughn: has joined #elixir-lang
[07:31:19] absolutejam1: has joined #elixir-lang
[07:37:10] mdbm_: serafeim, how much data can you insert in a cookie? you mentioned you reached once the cap limit
[07:37:39] serafeim: mdbm_: hmm... it's not that much. something like 4kb i think
[07:38:12] mdbm_: serafeim, yeah but how should I translate this in terms of amount of data that can be stored?
[07:38:48] serafeim: mdbm_: hm i'm not sure i guess it serialzies that data using some protocol (probably ETS)
[07:39:17] serafeim: mdbm_: thing is to only store primitives there and not data you can't control its size (i.e not arrays)
[07:39:25] mdbm_: serafeim, well in the end, what I really have is text in the cookie I guess, so I have to count in terms of UTF8 bytes?
[07:39:32] serafeim: i guess saving something like 10 strings or integers should be safe
[07:39:56] mdbm_: serafeim, cookies are text files right?
[07:40:19] serafeim: no. cookies are header lines to your http requests
[07:40:57] mdbm_: serafeim, yes and they are files as well
[07:42:14] serafeim: mdbm_: well they are saved as files in your computer
[07:42:27] serafeim: so that your browser will send them back to the server in order to keep a state
[07:44:26] mdbm_: serafeim, do you use not_qwerty123?
[07:44:37] serafeim: what's that ?
[07:45:10] celyr: has joined #elixir-lang
[07:45:17] mdbm_: serafeim, check strength of password
[07:45:35] serafeim: i don'tt know that
[07:45:55] mdbm_: nvm I check the code and it loads 40k+ common words (passwords) in to memory
[07:46:03] mdbm_: was wondering how much memory that consumes
[07:46:13] serafeim: not sure sorry
[07:46:35] CapNemo: has joined #elixir-lang
[07:48:33] serafeim: i don't mess with passwords that much we use LDAP for auth
[07:55:02] jeffro_: has joined #elixir-lang
[08:00:43] Sgeo__: has joined #elixir-lang
[08:09:32] lexmag: has joined #elixir-lang
[08:13:46] Bounga: has joined #elixir-lang
[08:14:05] jeffro_: has joined #elixir-lang
[08:16:45] Gika: has joined #elixir-lang
[08:22:03] ariedler: has joined #elixir-lang
[08:26:42] absolutejam: Can I have an Ecto `embeds_many` with different structs?
[08:28:23] lexmag_: has joined #elixir-lang
[08:28:25] absolutejam: at the minute I have a single struct definition that has mutually exclusive fields
[08:28:37] absolutejam: but I don't really like that approach
[08:29:08] josevalim: not with embeds_many
[08:29:19] josevalim: but using regular associations there are a couple different approaches
[08:29:25] josevalim: you can read more about them in the belongs_to macro docs
[08:40:10] jeffweiss: has joined #elixir-lang
[08:40:25] Gika: has joined #elixir-lang
[08:46:23] gde33: has joined #elixir-lang
[08:51:20] absolutejam: thanks josevalim
[08:52:31] lexmag: has joined #elixir-lang
[08:58:56] alexband: has joined #elixir-lang
[08:58:57] jeffro_: has joined #elixir-lang
[09:02:20] sangoma: has joined #elixir-lang
[09:04:28] Gika: has joined #elixir-lang
[09:18:43] gvaughn: has joined #elixir-lang
[09:26:18] slightlycyborg: has joined #elixir-lang
[09:26:52] slightlycyborg: hi. if i want to use @spec to specify a fn takes a paramater that implements a behaviour, can I do that?
[09:28:49] slightlycyborg: ok. turns out this is impossible.
[09:38:32] absolutejam1: has joined #elixir-lang
[09:42:06] serafeim: does anybody remember a coding quiz where you had to implement a virtual machine for a small computer and then you executed a program there which you had to hack in order to win ?
[09:42:30] serafeim: the program was something a text adventure
[09:44:42] serafeim: this was very trending 4-5 years ago i think
[09:58:37] lexmag: has joined #elixir-lang
[10:02:07] absolutejam: can anyone suggest me a method of caching some tailed data?
[10:02:31] absolutejam: for example, if I'm tailing some logs via. an API (from hundres to thousands or entries)
[10:02:58] absolutejam: I could use Redis or the likes but I dunno if there's an elixir/erlang native solution that is appropriate
[10:03:21] serafeim: absolutejam: use ETS ?
[10:03:21] absolutejam: like, would a genserver be enough? should I look mnesia, ets?
[10:03:52] absolutejam: it's basically so I can store the last x log entries or events and show them via. Phoenix/liveview
[10:04:04] serafeim: absolutejam: ETS should cover you
[10:04:10] absolutejam: I've not really touched on much 'beyond' genserver. I'll look at ETS, thanks
[10:04:41] serafeim: and also use this: https://github.com/sasa1977/con_cache
[10:05:50] serafeim: you'll probably need con cache because querying ETS leaves something to be desired: https://elixirschool.com/en/lessons/specifics/ets/
[10:07:33] BeerLover: has joined #elixir-lang
[10:21:02] lexmag: has joined #elixir-lang
[10:21:49] jeffweiss: has joined #elixir-lang
[10:22:10] mdbm: has joined #elixir-lang
[10:22:58] ariedler: has joined #elixir-lang
[10:25:28] jeffro_: has joined #elixir-lang
[10:28:45] voltone: has joined #elixir-lang
[10:38:53] purebadger: has joined #elixir-lang
[10:49:16] voltone: has joined #elixir-lang
[10:49:18] purebadger: has joined #elixir-lang
[10:55:08] ariedler: has joined #elixir-lang
[10:59:43] lexmag: has joined #elixir-lang
[11:04:03] BeerLover: has joined #elixir-lang
[11:04:09] targaf: has joined #elixir-lang
[11:06:57] gvaughn: has joined #elixir-lang
[11:09:16] BeerLover: has joined #elixir-lang
[11:16:14] BeerLover: has joined #elixir-lang
[11:24:33] joaj: has joined #elixir-lang
[11:26:49] lao-tzu: has joined #elixir-lang
[11:34:00] mdbm: if I use this constraint: validate_length(:password, min: 8, max: 128)
[11:34:13] voltone: has joined #elixir-lang
[11:34:15] mdbm: and the password is empty, it will pass it seems...
[11:34:29] mdbm: seems like I have to add: validate_required([:password])
[11:34:39] mdbm: but I don't understand as I have a min length required
[11:39:38] cjk101010: mdbm: you are right, that should be documented. Why not create a pull request? :-)
[11:41:19] mdbm: cjk101010, yeah sure, I've updated some doc already. Was not sure if my code was ok. Because in the Phoenix book it crashes for me if the password is empty, so they didn't use the required constraint therefore I thought I did something wrong
[11:44:07] zica: has joined #elixir-lang
[11:46:41] hypercore: has joined #elixir-lang
[11:47:12] BeerLover: has joined #elixir-lang
[11:49:35] BitBot: has joined #elixir-lang
[11:51:05] gde33: has joined #elixir-lang
[11:54:36] celyr: has joined #elixir-lang
[11:55:23] serafeim: let's suppose i have a query. Why this isn't working: `where_clauses = Enum.reduce(query, creat_where_clauses_reducer)`
[11:56:32] serafeim: oh well... forget it. rubber duck debug resqued me again
[11:57:41] Sgeo__: has joined #elixir-lang
[11:59:02] dsr: has joined #elixir-lang
[12:00:29] serafeim: another question. the `where` function (among others) gets an array of query positions as an argument ie `query |> where([a, b, c], c = 32)`. how could i create this [a, b, c] dynamically ?
[12:01:16] serafeim: i.e for a parameter that is 4th i'd like to create something like `[p0, p1, p2, p3]`
[12:02:14] lexmag: has joined #elixir-lang
[12:04:11] lexmag: has joined #elixir-lang
[12:05:42] BeerLover: has joined #elixir-lang
[12:08:27] duane: has joined #elixir-lang
[12:17:08] serafeim: is this even possible ? do i need to use macros ?
[12:19:57] BitBot: has joined #elixir-lang
[12:22:42] jeffro_: has joined #elixir-lang
[12:28:43] serafeim: i even asked on the elixir forum: https://elixirforum.com/t/create-dynamic-bindings-for-where-clause/23797 hope than somebody can asnwer
[12:34:11] nickjj: is it possible to have a generic config item supplied in config.exs but then in let's say another config (prod.exs), read in that config file and modify a component of that value without having to redefine it?
[12:34:44] nickjj: like if the config value were a map, i want to remove 1 key of the map -- without having to manually define the map again without that 1 key
[12:39:50] bturnbull: has joined #elixir-lang
[12:41:43] za1b1tsu: has joined #elixir-lang
[12:47:18] BitBot: has joined #elixir-lang
[12:55:28] gvaughn: has joined #elixir-lang
[12:55:31] tutti: has joined #elixir-lang
[12:57:09] BitBot: has joined #elixir-lang
[12:58:57] lexmag: has joined #elixir-lang
[13:06:34] ankhers: nickjj: I haven't tested, but I would assume you could use Application.get_env/3 within your config files. It is just Elixir code afterall. However, I would advise against trying to get too complex in your config scripts.
[13:07:33] nickjj: Ankhers, that is what i tried originally, then i did a string replace on the result of get_env but the end game config value was the result of get_env without the string replace's effect
[13:08:11] ankhers: Can you show some example code?
[13:11:03] nickjj: i had this in my prod.exs , config :hello, :someopt, fruit: String.replace(Application.get_env(:hello, :someopt), "apple", "orange")
[13:11:08] BeerLover: has joined #elixir-lang
[13:11:20] nickjj: and in config.exs i had the fruit set to "apple" -- but in prod.exs the value of :someopt was still apple
[13:12:22] nickjj: i was working with strings for now just to see if it would work, before i went ahead and used my real data structure
[13:13:12] nickjj: it's not the end of the world if i have to copy / paste things around but it would have been nice if i could modify it with code
[13:13:43] jeffro_: has joined #elixir-lang
[13:15:22] griffinbyatt: has joined #elixir-lang
[13:19:43] jeffro_: has joined #elixir-lang
[13:19:59] lexmag: has joined #elixir-lang
[13:27:52] BeerLover: has joined #elixir-lang
[13:27:52] jeffro_: has joined #elixir-lang
[13:29:35] ankhers: Okay. So the config function will not put the value into the application env immediately. It does put it in the process dictionary though. So what you may want to do is retrieve that value by using `Process.get({Mix.Config, :config})[:my_app]'. This will give you the entire configuration for that application. However, this seems like it is getting into private API territory.
[13:30:48] ankhers: nickjj: ^^
[13:32:12] PragTob: has joined #elixir-lang
[13:32:22] nickjj: Ankhers, thanks. i think you're right in that it's probably doing things i shouldn't be doing
[13:32:24] lexmag: has joined #elixir-lang
[13:34:03] Saukk: has joined #elixir-lang
[13:35:26] alexband: has joined #elixir-lang
[13:38:35] absolutejam: has joined #elixir-lang
[13:38:52] gvaughn: has joined #elixir-lang
[13:41:42] klaw1: has joined #elixir-lang
[13:41:56] lexmag: has joined #elixir-lang
[13:42:07] celyr: has joined #elixir-lang
[13:46:55] jeffro_: has joined #elixir-lang
[13:53:38] BitBot: has joined #elixir-lang
[13:54:21] nineczar: has joined #elixir-lang
[13:55:46] jeffweiss: has joined #elixir-lang
[14:03:59] serafeim: Nicj the answer is yes
[14:05:09] serafeim: Check the config files here https://github.com/spapas/phxcrd/tree/master/config
[14:15:23] jeffro_: has joined #elixir-lang
[14:21:11] purebadger: has joined #elixir-lang
[14:41:22] lexmag: has joined #elixir-lang
[14:42:58] jeffweiss: has joined #elixir-lang
[14:43:39] lexmag: has joined #elixir-lang
[14:48:09] Phylock: has joined #elixir-lang
[14:59:08] imranismail: has joined #elixir-lang
[15:06:32] duane: has joined #elixir-lang
[15:15:45] Sgeo_: has joined #elixir-lang
[15:16:59] drrty: has joined #elixir-lang
[15:22:17] aalmazan: has joined #elixir-lang
[15:25:08] jeffweiss: has joined #elixir-lang
[15:27:04] tuacker: has joined #elixir-lang
[15:30:34] serafeim: could anybody help with this: https://elixirforum.com/t/create-dynamic-bindings-for-where-clause/23797 ? TIA !
[15:33:58] drrty: has joined #elixir-lang
[15:35:16] josevalim: serafeim: see my previous replies on the forum
[15:35:21] josevalim: I have a similar example
[15:35:30] drrty: has joined #elixir-lang
[15:35:39] josevalim: serafeim: you can also go to the ecto repo and search for the dynamic queries guide
[15:35:47] orbyt_: has joined #elixir-lang
[15:35:57] josevalim: I would send a link but I am not away from computer
[15:36:58] drrty: has joined #elixir-lang
[15:50:52] serafeim: Thanks josevalim for any help! Are you talking about using `dynamic` or there's some other guide?
[15:56:52] pera: has joined #elixir-lang
[15:57:23] serafeim: Because i don't think `dynamic` is useful in my case :(
[16:00:00] serafeim: I'm pretty sure that I need to use metaprogramming to solve my problems but I'm completely unfamiliar with that and my head exploded when I tried learning it
[16:05:37] Bounga`: has joined #elixir-lang
[16:05:37] imranismail: has joined #elixir-lang
[16:06:07] imranismail: has joined #elixir-lang
[16:06:38] BeerLover: has joined #elixir-lang
[16:07:27] imranismail: has joined #elixir-lang
[16:07:57] icecreamcohen: has joined #elixir-lang
[16:08:15] laut: has joined #elixir-lang
[16:18:23] sangoma: has joined #elixir-lang
[16:28:09] nickjj: is it common practice / idiomatic to do: use HelloWeb, :view , in your view helper files?
[16:34:03] ankhers: nickjj: Do you mean the foo_view.ex files?
[16:34:52] nickjj: Ankhers, a foo_helpers.ex file that lives in views/ , this is the spot to put functions that help you display things right?
[16:35:22] ankhers: I generally put them in the view files themselves.
[16:35:59] ankhers: Unless it is common to multiple views, then I create a new module for them.
[16:36:00] nickjj: for example a def full_name(first, last) function that would return "#{first} #{last}"
[16:36:24] ankhers: Unless you need the stuff the `use' brings along with it, don't do it.
[16:36:50] nickjj: in this case i'm using things like img_tag, routes helpers and rendering partials
[16:37:12] nickjj: so i'm finding myself maybe wanting to use it (since all of that stuff is set up by the view macro in hello_web.ex
[16:37:23] nickjj: but at the same time it seems maybe wrong since it's not technically a view module?
[16:38:03] ankhers: You can always create another entry in your hello_web.ex file for view_helper or something that only brings in what you need.
[16:39:57] ankhers: Though, to be honest, I am not really sure what the most idiomatic thing to do is.
[16:40:33] nickjj: yeah, initially i put them in foo_view.ex but then i read that the view file should only be used for handling rendering actual templates
[16:40:49] nickjj: like if you wanted to render a json response or something, you'd put it there
[16:44:26] foggyboi: has joined #elixir-lang
[16:44:47] jeffro_: has joined #elixir-lang
[16:46:12] tallysmartins_: has joined #elixir-lang
[16:47:55] squalloster: has joined #elixir-lang
[16:52:02] Disorganized: has joined #elixir-lang
[16:55:11] DTZUZO: has joined #elixir-lang
[17:07:20] foggyboi: has joined #elixir-lang
[17:15:54] Disorganized: has joined #elixir-lang
[17:17:51] jeffro_: has joined #elixir-lang
[17:24:10] lexmag: has joined #elixir-lang
[17:25:34] purebadger: has joined #elixir-lang
[17:27:41] drincruz: has joined #elixir-lang
[17:31:19] Sgeo_: has joined #elixir-lang
[17:32:30] Disorganized: has joined #elixir-lang
[17:34:08] jeffro_: has joined #elixir-lang
[17:34:13] drrty: has joined #elixir-lang
[17:37:08] Disorganized: has joined #elixir-lang
[17:44:31] Disorganized: has joined #elixir-lang
[17:46:27] DTZUZO: has joined #elixir-lang
[17:47:38] jeffweiss: has joined #elixir-lang
[17:48:07] serafeim: i've clarified more my question in case anybody can help: https://elixirforum.com/t/create-dynamic-bindings-for-where-clause/23797/3 TIA
[17:51:09] zica: has joined #elixir-lang
[18:00:28] pupoxcu: has joined #elixir-lang
[18:02:13] jeffweiss: has joined #elixir-lang
[18:08:27] Disorganized: has joined #elixir-lang
[18:16:34] pera: has joined #elixir-lang
[18:19:29] hypercore: has joined #elixir-lang
[18:26:35] jeffro_: has joined #elixir-lang
[18:27:50] wsieroci: has joined #elixir-lang
[18:29:59] alexband_: has joined #elixir-lang
[18:32:46] mahmudov: has joined #elixir-lang
[18:36:18] nickjj: does anyone else find it more difficult to read forum posts after the updates? the white on white makes it much more difficult to glance replies
[18:38:23] ankhers: I'm used to it from the nixos forums.
[18:40:46] foggyboi: nickjj: tbf I didn't notice until you said something but yes, this is harder to read
[18:47:31] purebadger: has joined #elixir-lang
[18:56:08] benwilson512: did the forum CSS break?
[18:58:38] ankhers: The sponsors section at the bottom of a thread does not seem to be working.
[19:07:29] serafeim: yes the sponsors isn't working for me also but i thought that it was because of my ad blocker :/
[19:08:13] netrino: has joined #elixir-lang
[19:11:33] serafeim: also I updated my question with a very detailed description of the problem so for anybody that has time to look at it ... https://elixirforum.com/t/create-dynamic-bindings-for-where-clause/23797/6
[19:17:08] drrrty: has joined #elixir-lang
[19:19:34] Exuma: has joined #elixir-lang
[19:20:20] nickjj: i hope you get an an answer serafeim, that seems like a really useful thing to have
[19:21:25] serafeim: nickjj: thank you
[19:36:33] Exuma: what ifle do i put this in
[19:36:34] Exuma: for phoenix
[19:36:35] Exuma: config :app, App.Repo, migration_primary_key: [name: :uuid, type: :binary_id]
[19:36:50] gamache: Exuma: config/config.exs is a good guess
[19:36:51] jer: in one of your configs in config/ dir
[19:36:59] jer: i.e., dev.exs for development
[19:38:14] Exuma: actually.. how do i change the primary key for 1 table only
[19:38:23] Exuma: i have an md5 string column i want to use instead of id
[19:39:24] Exuma: nevermind, i found
[19:57:54] nineczar: has joined #elixir-lang
[20:08:15] Sgeo__: has joined #elixir-lang
[20:09:23] Disorganized: has joined #elixir-lang
[20:13:11] icecreamcohen: has joined #elixir-lang
[20:18:50] slightlycyborg: has joined #elixir-lang
[20:19:42] subsonik: has joined #elixir-lang
[20:27:16] jeffro_: has joined #elixir-lang
[20:39:34] ur5us: has joined #elixir-lang
[20:41:05] Exuma: has joined #elixir-lang
[21:04:51] nineczar: has joined #elixir-lang
[21:12:20] Exuma: has joined #elixir-lang
[21:12:36] jeffweiss: has joined #elixir-lang
[21:16:20] jeffro_: has joined #elixir-lang
[21:20:37] Disorganized: has joined #elixir-lang
[21:23:05] jeffweiss: has joined #elixir-lang
[21:36:28] bturnbull_: has joined #elixir-lang
[21:50:35] Exuma: has joined #elixir-lang
[21:53:01] icecreamcohen: has joined #elixir-lang
[22:01:06] DTZUZO: has joined #elixir-lang
[22:03:16] gvaughn: has joined #elixir-lang
[22:04:36] Exuma: how do i stack pattern matching in case do
[22:04:51] Exuma: x -> something
[22:04:54] Exuma: something else
[22:17:37] slightlycyborg: has joined #elixir-lang
[22:19:40] slightlycyborg: Hi. If I have 2 GenServers and I use a single Task Supervisor and Task.Supervisor.async_nolink to start and monitor tasks started by the 2 GenServers, will the result of fn be sent to the appropriate GenServer?
[22:20:08] jeffro_: has joined #elixir-lang
[22:28:15] drincruz: has joined #elixir-lang
[22:28:46] griffinbyatt: has joined #elixir-lang
[22:39:17] Exuma: has joined #elixir-lang
[22:40:54] slightlycyborg: Also, what do you think of using files with the same names in different paths/modules? The alternative would be to prefix the file name with "<parent_dir>_"
[22:46:04] gvaughn_: has joined #elixir-lang
[22:52:14] drincruz: has joined #elixir-lang
[22:54:03] Disorganized: has joined #elixir-lang
[22:55:01] OvermindDL1: Exuma: What do you mean by stack pattern matching?
[22:55:14] Exuma: eh i just meant putting multiple conditions on top of each other
[22:55:19] OvermindDL1: Do you mean multiple heads pointing to the same body?
[22:55:30] OvermindDL1: There are a few ways depending on precisely what you are matching
[22:55:48] OvermindDL1: In essence you just need to 'merge' the conditions
[22:55:56] OvermindDL1: Can you give a specific example that you want to merge?
[22:55:56] Exuma: yeah its all ogod i just moved on
[22:56:08] Exuma: now im stuck on trying to do a select for update with phoenix
[22:56:23] OvermindDL1: for update? o.O
[22:56:40] Exuma: SELECT ___ FOR UPDATE lock
[22:56:49] Exuma: i feel like im trying to eat soup with a spoon any time i use ecto
[22:56:54] Exuma: i feel absolutely retarded
[22:57:02] OvermindDL1: Ah, that wouldn't be phoenix, that would be ecto
[22:59:05] OvermindDL1: That's a great question actually, might need to be a feature request for ecto...
[22:59:10] OvermindDL1: I'd recommend posting it on the forum
[22:59:34] OvermindDL1: Are you really needing to optimistically lock those rows though?
[22:59:58] OvermindDL1: The transaction will keep it safe and the speed benefit for it will only be minor (or even worse, situation depending)
[23:00:41] alex88: has joined #elixir-lang
[23:01:09] Exuma: i have 5-10 incoming requests which will be happening all milliseconds apart, and i need only 1 of them to write to the DB, all the rest need to not change anything
[23:01:31] Exuma: this is based on an md5 hash of several fields to build a key
[23:01:57] Exuma: so i have.. say.. 10 incoming requests with that key, and the first one needs to write that key with some other data. then all othre requests need to be locked until the insert finishes so that it can see they exist
[23:04:23] OvermindDL1: Hmm, unsure if https://hexdocs.pm/ecto/Ecto.Changeset.html#optimistic_lock/3 could help in any way, it would require fetching them first and you'd still have a race, but in a transaction even if work is duplicated then only one will succeed anyway...
[23:04:32] OvermindDL1: You could just serialize them through a single GenServer too
[23:05:17] Exuma: i will be handling ~1000 req/second so i need multiple servers, otherwise i def would put it in a genserver
[23:05:46] OvermindDL1: Ahh, hmm, how often will this duplicate submits happen?
[23:06:29] OvermindDL1: Because this really sounds like pessimistic locking now
[23:06:52] Exuma: it will be nearly 100% of the time
[23:07:12] OvermindDL1: Then why not use `Query.lock` on your select then?
[23:07:25] Disorganized: has joined #elixir-lang
[23:07:40] Exuma: im basically handing 10 independent ad requests, and due to the logistics of where the ads are being shown i can't give them a unique identifier. i have to just handle this huge influx of data, hash them, and only 1 will need to be written
[23:07:52] Exuma: is that select for update? what is query.lock
[23:07:53] OvermindDL1: https://hexdocs.pm/ecto/Ecto.Query.html#lock/2
[23:08:06] Exuma: oh yeah, that is what i mean
[23:08:08] purebadger: has joined #elixir-lang
[23:08:10] Exuma: SELECT __ FOR UPDATE in a transaction
[23:08:17] Exuma: i was looking for that
[23:08:23] OvermindDL1: Ah cool then. ^.^
[23:08:29] Exuma: ok 1 more question...sooo
[23:08:32] Exuma: let me show some code fast
[23:08:50] OvermindDL1: I'm actually about to start driving, ping me in like 10-15 minutes and I should be home if no one has answered it by then? :-)
[23:09:05] OvermindDL1: I.E. ask it anyway to see if anyone else sees it. :-)
[23:09:18] Exuma: ok thanks!
[23:09:19] Exuma: https://pastebin.com/x7PFt9dV
[23:09:44] Exuma: right now there is no transaction (ive never really used ecto)
[23:10:13] Exuma: but, i have my ecto queries in those 3 methods (get_ads, update_ads, put_ads)
[23:10:31] Exuma: im not sure if i can just wrap the entire thing in a transaction and call it a day. part of me thinks the answer is no because functionally speaking nothing is ever that easy
[23:10:37] Exuma: so im not exactly sure how to handle this
[23:10:41] Exuma: the code structure, that is
[23:10:50] Exuma: because the transaction starts in 1 method, and ends in another method
[23:11:09] Exuma: it would start in get_ads with the lock, and then update_ads or put_ads would need to close the transaction
[23:13:58] Disorganized: has joined #elixir-lang
[23:15:26] Exuma: i suppose i could make a unique index and just silently fail when that happens
[23:15:40] Exuma: def not as ideal though
[23:17:37] micro`: has joined #elixir-lang
[23:18:50] hypercore: has joined #elixir-lang
[23:19:49] Exuma: on second thought i definitely cant do that i just realized
[23:19:53] Exuma: for some other reason
[23:23:02] jeffro_: has joined #elixir-lang
[23:25:28] ariedler: what are you trying to do lol
[23:26:27] Exuma: right now i am trying to get a pessimistic lock on Repo.get_by(Impression, hash: hash)
[23:26:48] OvermindDL1: Locks really only mostly make sense in a transaction
[23:27:06] OvermindDL1: And you should learn Ecto.Multi, it makes transaction handling easy to pipe through
[23:27:06] Exuma: i want a transaction, i am mostly dealing iwth ecto headache
[23:28:59] Exuma: ok i will look into that
[23:29:07] Exuma: off hand, do you know how i access the results of this?
[23:29:09] Exuma: impression = Ecto.Query.from(i in Impression, where: i.hash == ^hash, lock: "FOR UPDATE")
[23:30:00] OvermindDL1: That's just a query, you have to run it to get results, Repo.*, like Repo.all or so
[23:30:33] ariedler: also since you are locking for update; you will need to use Ecto.multi
[23:30:50] Exuma: ok, let me do something quick then with pastebin
[23:30:54] ariedler: and be in a transaction of course
[23:31:09] OvermindDL1: Eh don't really 'need' to, Ecto.transaction is fine by taking a function on its own, but a multi definitely makes things more streamlined
[23:32:01] Exuma: im doing the following:
[23:32:02] Exuma: https://pastebin.com/A1fErtj2
[23:32:30] Exuma: https://pastebin.com/8zXm2daJ
[23:32:38] Exuma: so... using multi aside, does that structure look OK?
[23:32:43] OvermindDL1: Can't insert a select query
[23:32:44] Exuma: if so, i will move on to trying to convert these to "multi"
[23:33:22] orbyt_: has joined #elixir-lang
[23:34:08] Exuma: hmm, yes i suppose youre right
[23:34:10] Exuma: what a headache
[23:35:14] OvermindDL1: Same as sql. ^.^
[23:35:30] Exuma: yeah, i dont really use pessimstic locking so i am learning as i go
[23:35:43] Exuma: so how might you solve this dilemma?
[23:37:49] OvermindDL1: Definitely write an Ecto.Multi. ^.^
[23:38:07] Exuma: what i mean is, how would you handle the fact that you cant do INSERT with a SELECT FOR as there is no row to lock onto?
[23:38:34] OvermindDL1: Inserting on a select like that doesn't make sense, you aren't inserting anything?
[23:40:17] Exuma: here is basically what is happening.. i have 10 requests coming in all simultaneously. if the record doesnt exist (based on the hash) it needs to call Feed.fetch *one time*, and insert that data in a single row. I can't insert multiple rows, and i cant call Feed.fetch more than once (because its also tracking)
[23:40:37] Exuma: update is similar.. if the record exists.. i need to check if its fresh (< 10 seconds old)
[23:40:39] OvermindDL1: Can't call feed.fetch multiple times?
[23:40:41] Exuma: if its fresh, i just do nothing
[23:40:44] OvermindDL1: And I'm guessing this is not a DB query?
[23:40:47] Exuma: yeah in my pastebin
[23:40:55] OvermindDL1: In that case you definitely need to serialize it on the application side
[23:40:58] Exuma: no its an API query that has stats tracking built into the API side
[23:41:17] OvermindDL1: I'd probably use Cachex or so honestly, just to be lazy about it, have it query it once and cache it for X amount of time
[23:41:39] Exuma: does it go across servers?
[23:41:59] OvermindDL1: It has a couple of backends, so it depends on the mode on which you set it up
[23:42:16] OvermindDL1: Otherwise you can just try inserting a row with a key in the database and if it works then do it, if it fails then something else is already doing it
[23:42:19] OvermindDL1: That way the DB syncs it
[23:42:33] OvermindDL1: Oban as a secondary job process might even be better too if you can do it async
[23:42:43] Exuma: the problem is i dont know the key, because that comes from the API request :X
[23:42:44] alexband: has joined #elixir-lang
[23:42:57] Exuma: well actually h/o let me check that
[23:42:59] OvermindDL1: Then how do you know how to 'batch' those calls?
[23:44:36] Exuma: actually i take that back, i misspoke. the hash comes from the request parameters. I am still confused how to handle multiple inserts though
[23:44:56] Exuma: it cant be async, needs to be realtime
[23:45:28] OvermindDL1: Eh, you have a DB anyway, just insert a row with that hash and if you succeed then do the rest of the task, if you fail then wait until the data exists then return that (if you are returning anything)
[23:45:31] ariedler: so attempt insert; and then read if insert fails due to constraint on the hash
[23:45:52] OvermindDL1: And gotta go (mostly, be walking around in an out). ^.^
[23:45:52] Exuma: what im inserting involves the API call though
[23:46:19] Exuma: unless i create the column first, wait until it saves, then attempt an update on that (so 2 queries)
[23:49:25] OvermindDL1: Or just use another table to hold the the fact a request started
[23:49:52] Exuma: that is a good idea
[23:50:03] OvermindDL1: Can even have a timeout so if 'that' column has a row you need but no data in at after 30 seconds or whatever, then it might have died so try to have something else try it (increment a counter on it to try to 'acquire' it?)
[23:50:08] nickjj: Exuma, i ran into a chicken / egg problem recently where i ended up doing the insert + update and it worked really nicely
[23:50:29] Exuma: nickjj so you had a similar issue to mine, and you first did an insert and then select for update?
[23:50:37] nickjj: basically i inserted a record with a status of active = false and then after i got a confirmation from something, i updated it to true
[23:50:50] nickjj: and the app itself only deals with active thing
[23:50:59] OvermindDL1: I generally don't do updates in mine but I like to keep perfect history
[23:51:06] Exuma: alright, yes i do like that idea. the one concern i have is this will be 100's-1000s of queries per second volume wise
[23:51:14] Exuma: so i was trying to avoid that, but... i dont see away around it
[23:51:16] Exuma: and i do like that idea
[23:51:46] OvermindDL1: You need a synchronization point somewhere, especially since you need to call an out-of-db potentially slow call
[23:53:14] nickjj: it's strange because that pattern isn't obvious at all, i actually think OvermindDL1 may have recommended it haha, i honestly forgot
[23:56:34] Exuma: hmm ok, thanks guys
[23:56:36] Exuma: i will mull this over