JoeZMar
What is an efficient way to find out if a user_id is within a struct that contains multiple lists in any of the lists?
I have a struct that contains 5 keys each with a list as the value.
I want to see if a user_id is actively searching in any of the categories (each individual list). If they are it should halt and return true.
I tried Enum.each over the struct, but it says that the protocol isn’t implemented.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
Maybe
axelson
Well if you keep your data structure the same then you’ll have to do a linear search through each list. If you change your datastructure (or build a complementary one) then you can improve the performance of this search. But that’s probably only worth it if you are doing this search many times or if the size of the lists is quite large.
idi527
One easy way would be a
:setets table with user ids as keys and a list of “lists” (if they overlap) as values:Or a
:duplicate_setets table with user id as the key and one of lists as the value:Eiji
A bit better:
Important differences:
As a developer I absolutely never assume that anything will not change - especially when you are working for startups.
is_list/1guard).This is more problematic if you are looking on all keys - especially if
keysparameter is passed dynamically.Map.take/2is just designed for such things)In short my way is basically easier to modify on everyone’s needs.
I’m not sure, but maybe you are saving
user_idasPostgreSQL’sarray. In such case I strongly recommend to use relation and performSQLsearch which should be faster and safer (duplicated id constraint etc.).@idi527
:etsand even:dets(if there is such need) are option too, but I don’t see that every newbie would understand what you mean. Even I don’t remember this topic well as I did not need them recently. I believe that well documentedElixirfunctions are better at start.For beginners which want to use really big enumerable(s) I recommend to take a look at
Streammodule and evenflowlibrary if there is such a need. Both are also well documented and should not cause bigger problems.JoeZMar
I’ll elaborate a little bit as to what I’m working on.
I am creating a bot for a marketplace that is limited to 6 items. When a user decides they want an item(s) they would typically have to refresh the browser until someone else drops it on the “trading board”.
I have two GenServers that I figured could solve this. One is responsible for the botting commands (Using Hound it creates new session, logs in, selects item..) and the other is responsible for delegating who gets to pick up from the board next and sending a msg to their process to pick up an item.
The second GenServer is the one in question and it holds a struct of user_ids per each item (%StructName{ exclusive_item1: [1,2,3], exclusive_item2: …}.
When exclusive_item1 gets posted to the board after the bot has been running for a few hours (the typical amount of time for one to drop) I want it to grab the first user_id from exclusive_item1. The users have to be ordered because it should delegate the item to the person who’s waited the longest.
I have read a lot about ETS and DETS, but never implemented them. I’m essentially spending the next year of my life dedicating myself to Elixir. I left my Rails job to continue traveling and I plan on hiring some sort of consultant to make this investment of time really worth it. I don’t mind reaching for some of the more advanced tools right now because this is what my time is for, but I also want to make sure I have a solid understanding of the fundamentals.
Edit: Obligatory permission from site owner has already been granted as I am testing out new features for their company to show proof of concept.
JoeZMar
What’s considered a big enumerable? The map I was trying to Enumerate over has 5 keys and each had an empty list except one. When I was getting the protocol error for
Enumand it suggested Stream that was my first thought, but looking at the two functions I couldn’t figure out whyEnum.eachfailed but Stream did not. I then wondered if it had something to do with Stream’s compostability and I was probably just messing that up too.Eiji
You probably did not started
StreamHere is small example:
Tip:
Streamis automatically started when you pass it to anyEnumfunction. This is useful in some cases.Firstly it’s not possible to pipe value, because this function returns
:ok. You can deal with it only by passing function which is bad way, because loop will not stop when you will find value.JoeZMar
This is more what I was trying
Enumerate over the initial struct then check if the current user_id is a member of the list.
Eiji
as said
eachis bad here -Enum.find/2as we suggested is much betterEiji
If you have some time for this I suggest to use developer tools and find server private API. Of course private API could change at any time without control you can always debug it well. Simple task which run once a day and do something without submitting should be ok for most cases. I generally don’t like
houndas its doing heavy browser job which could be reduced (for some experienced people is just a matter of day or less - rarely more - depends on complexity). I have experience with writing scrapers, so for me it’s trivial task.Looks like a typical scenario for database. Probably
SQLite 3ormnesia(:disc_copiesmode). I really likemnesialast time as its pretty easy to work with multiple nodes without creating standalone database somewhere.ecto(database wrapper) should have good support for both of them. With database you do not need to worry about memory usage. For sure here you are storing only ids, but later you maybe would like to store also some extra data. Things are changing and extra limiting at start is mostly bad way.I suggest to create schema like:
with this (and of course
ItemandUserschema + migrations) you can easily write query in which you order byidfield.