|
no_funeral posted:i'm mostly worried about the production environment, which is a unicorn server. since unicorn is process based, i don't think it will be an issue? It will be an issue. Just get rid of the time zone change in the first place (sounds like a huge-rear end code smell), or make sure that you clean that poo poo up. Smol fucked around with this message at 11:18 on Nov 7, 2015 |
# ? Nov 7, 2015 11:14 |
|
|
# ? Apr 29, 2024 18:19 |
|
Smol posted:It will be an issue. Just get rid of the time zone change in the first place (sounds like a huge-rear end code smell), or make sure that you clean that poo poo up. Yup. Once you change the Time.zone for the process it will remain changed until you reset it. We wrap our user-centric actions in an around_filter that sets/unsets the Time.zone to where the user specified.
|
# ? Nov 7, 2015 20:14 |
|
Learning Ruby for the first time working through the Codecademy stuff, and I got to the sorting section. It almost broke my brain for a bit trying to figure out how the hell things were actually working, and it occurs to me maybe my pain would be helpful. When sorting an array, the .sort method uses the combined comparison comparison or "spaceship" operator (which looks like <=> ) to compare two elements of the array at a time returning -1, 0 , or 1:code:
If n1 == n2, the comparison returns 0 If n1 > n2, the comparison returns 1 Why does this matter for sorting? Sort compares the two elements and does the following:
If the comparison returns 0 or -1 it doesn't swap their positions The swapping positions part was what was tripping me up in understanding sorting; because I was incorrectly reading it like this:
If the comparison returns 1, the number on the left should be second My confusion was initially compounded because this incorrect reading technically works, but only for ascending order. When I tried it in descending order I struggled trying to follow the steps because I was making the wrong step in how sort uses the returned comparison. For example: code:
code:
I'm totally new at Ruby so if my understanding is still woefully incorrect please fell free to correct me; I know the sort method steps through things in a bit more complicated manner than that as it clearly iterates through the array more than one time to make sure sorting is completed.
|
# ? Nov 8, 2015 20:58 |
|
Mo_Steel posted:I'm totally new at Ruby so if my understanding is still woefully incorrect please fell free to correct me; I know the sort method steps through things in a bit more complicated manner than that as it clearly iterates through the array more than one time to make sure sorting is completed. Ruby uses Quicksort under the hood to sort Arrays (and Enumerables):
Quicksort is O(n * log(n)) on average and O(n^2) worst case. In english, that means Quicksort can sort a list with 10 elements in about 23 steps on average and 100 steps at worst. That's pretty good for a sorting algorithm, which is why Quicksort is extremely common. Have a look at the Algorithm section of the Quicksort Wikipedia page for a basic explanation of the algorithm. MrPablo fucked around with this message at 02:32 on Nov 9, 2015 |
# ? Nov 9, 2015 02:30 |
|
EVGA Longoria posted:At my current company, we do SE 1-3, Sr SE and then Architect. Lead is another path that replaces Senior/Architect. It makes sense to me, so that's how I'd think. At 10+ years, I would expect so one to be applying for one or the other explicitly. Whats the diff? To me, Lead has some management stuff going on - people stuff.
|
# ? Nov 9, 2015 03:28 |
|
KoRMaK posted:Whats the diff? Lead does have management stuff. Not everyone wants to do management.
|
# ? Nov 9, 2015 03:45 |
|
MrPablo posted:Ruby uses Quicksort under the hood to sort Arrays (and Enumerables): Cool stuff, a pivot value never occurred to me but I can see how that would cut down on time to sort compared with just repeatedly checking all values with their neighbors until you never get a swap response.
|
# ? Nov 9, 2015 04:57 |
|
Let's say something went wrong in production and you have to do some database surgery through ActiveRecord. What's the safest, most accepted way of hotfixing live, production data? The original method I was taught, "create a Ruby script and load it from Rails console while pointing to our production database", just doesn't sit right with me. We have no canonical way of hotfixing our database issues, though, so in lieu of anything else, that's the default approach. Is there something better?
|
# ? Nov 11, 2015 15:57 |
|
Got a backup? I have been known at times to log into the production console and do stuff. Or, write a migration.
|
# ? Nov 11, 2015 16:06 |
|
Pollyanna posted:Let's say something went wrong in production and you have to do some database surgery through ActiveRecord. What's the safest, most accepted way of hotfixing live, production data? For a small, one-off fix that just needs to get done, I'd be awfully tempted just to use rails console, with an appropriate amount of caution.
|
# ? Nov 11, 2015 17:39 |
|
Yeah, I'll usually do that through rails console, just make sure you don't gently caress it up. If it's a bigger batch of changes, you can write a migration or do it through db:seed.
|
# ? Nov 11, 2015 17:58 |
|
Yeah, depends on the scope of the adjustments. Super simple one-liners or just touching a handful of records (if this is the case make sure you're only touching these records!) dropping into production console is fine. Just 1) backup first, 2) be careful. If it's something more involved I will write a one-off rake task and test it against a copy of production first
|
# ? Nov 11, 2015 18:35 |
|
Sounds good to me. I made a spec that mimicks our current issue and from what I can tell, the script/class/module/thing-I-made handles it correctly. I guess logging into console works well. I tested it on my local copy of our DB, and it works there too. We don't do production DB backups at my place, though, as far as I know. At least, not regularly. Something about it being too much data, or whatever.
|
# ? Nov 11, 2015 19:03 |
|
It's too much data, so if it's lost then it's easier to replace than a backup hard drive?
|
# ? Nov 11, 2015 19:30 |
|
Pollyanna posted:Let's say something went wrong in production and you have to do some database surgery through ActiveRecord. What's the safest, most accepted way of hotfixing live, production data? Home projects, Rails console. At work, has to be a migration, with the usual code review and testing etc that accompanies any other production code change.
|
# ? Nov 11, 2015 19:48 |
|
Pollyanna posted:We don't do production DB backups at my place, though, as far as I know. At least, not regularly. Something about it being too much data, or whatever.
|
# ? Nov 11, 2015 20:05 |
|
Pollyanna posted:Sounds good to me. I made a spec that mimicks our current issue and from what I can tell, the script/class/module/thing-I-made handles it correctly. I guess logging into console works well. I tested it on my local copy of our DB, and it works there too. We have a 1.5TB database at my day job that's fully backed up to S3 daily... What's your excuse for not caring about your business's data at all? Thalagyrt fucked around with this message at 20:21 on Nov 11, 2015 |
# ? Nov 11, 2015 20:18 |
|
Maybe they don't have a station wagon big enough.
|
# ? Nov 11, 2015 20:19 |
|
KoRMaK posted:Maybe they don't have a station wagon big enough. lol. never underestimate the bandwidth of a station wagon full of hard drives
|
# ? Nov 11, 2015 20:21 |
|
Peristalsis posted:For a small, one-off fix that just needs to get done, I'd be awfully tempted just to use rails console, with an appropriate amount of caution. One time in the production console, I wanted to filter an array of all users to find those that belonged to a certain team. code:
|
# ? Nov 13, 2015 13:02 |
|
Ahhh please everyone if you don't use a Postgres service that sets up wal shipping for you so you have point in time recovery, please set that up right now.
|
# ? Nov 13, 2015 16:29 |
|
Pardot posted:Ahhh please everyone if you don't use a Postgres service that sets up wal shipping for you so you have point in time recovery, please set that up right now. Yeah, my sysadmin saved me using something like that. This was 5 years ago though.
|
# ? Nov 13, 2015 16:35 |
|
Pardot posted:Ahhh please everyone if you don't use a Postgres service that sets up wal shipping for you so you have point in time recovery, please set that up right now. What about MySQL? Also we do migrations that go through the normal review process for any data changes like that.
|
# ? Nov 14, 2015 16:05 |
|
Sewer Adventure posted:Because it was a has_one relation, assignment doesn't need a save call When I ever have to use the production console like that I make sure to use sandbox mode.
|
# ? Nov 14, 2015 16:23 |
|
So, quick question; I came from a background of having done some code in C#, and I'm looking at the "yield" functionality in Ruby, like this:code:
code:
Mo_Steel fucked around with this message at 05:08 on Nov 25, 2015 |
# ? Nov 25, 2015 04:56 |
|
code:
necrotic fucked around with this message at 05:31 on Nov 25, 2015 |
# ? Nov 25, 2015 05:27 |
|
Ruby basically allows every method to take a block (think of it as an anonymous function) as a parameter. "yield" simply calls that block with whatever parameters you give it.
|
# ? Nov 25, 2015 06:39 |
|
Alright, thanks for the additional information.
|
# ? Nov 25, 2015 06:43 |
|
Mo_Steel posted:Alright, thanks for the additional information. I think one of the best examples of the usefulness of yield is Enumerable#each. It's such a simple thing, and so perfectly elegant once you realize what's going on. code:
From there, I'm sure you can start to see other uses for yield. Another great example is structuring markup languages. code:
|
# ? Nov 25, 2015 18:43 |
|
Mo_Steel posted:
I'm still reeling from this talk
|
# ? Nov 25, 2015 20:09 |
|
I'm not sure if this is a Rails issue, a VM issue, or a MySQL issue, but I'll start here and hope for the best. Our app has a Datafile model, which just stores OS file metadata, and a DatafilePermission model, which links datafiles to users who have specific accesses to the files. In our code is this command: code:
code:
I bumped the memory allocated in my Vagrantfile from 2 GB up to 12 GB (my PC only has 16, so I can't really go much higher), and it didn't solve the problem. I also destroyed and rebuilt my Vagrant box (which was a pain, as the Vagrantfile is a bit out of date in terms of setting everything up), on the assumption that my VM image might be corrupted, but the problem persists. My datafiles table has 13,537 rows, and the datafiles_permissions table has just over 18,257 rows. If I limit the output of the query, using code:
The explain feature doesn't tell me much: code:
code:
So - does anyone have any suggestions? I guess I could try scrapping the includes method, and constructing the list with lower-level commands, but this was changed to use includes to resolve an n+1 queries problem that was bogging things down and making the screens with datafiles pretty much unusable. I'm not finding much of use on Google, and the only other thing I can think of to try is to start updating components (MySQL, Virtual Box, etc.), and hope some update magically fixes this error. I'd like to avoid that, because I still won't know if we have a bit of code that might blow up again at some point, and also because I don't want to end up breaking some gem version dependency just to track down a stupid bug that only affects me to begin with. Edit: Is it possible that something in the environment settings could cause this? Since this is dev, could there be some setting that causes rails to try to do too much - like extra logging, or not caching something that clogs up the memory? Edit 2: I replaced development environment file with the production environment file, and nothing changed, so that can't be the issue. Peristalsis fucked around with this message at 23:07 on Nov 27, 2015 |
# ? Nov 27, 2015 20:58 |
|
Peristalsis posted:Datafile model stuff quote:Datafile.includes(datafile_permissions: [:user]) quote:Datafile.includes(:datafile_permissions).where('datafile_permissions.user_id = ?', current_user.id).references(:datafile_permissions)
|
# ? Nov 28, 2015 16:48 |
|
Cock Democracy posted:I'd be interested in seeing the model code for Datafile and DatafilePermission. Maybe they are set up wrong somehow. It could be the nested loading (Datafile -> Permissions -> Users) causing issues. What happens if you do the same thing in a script, not a Rails console? It could be an issue "rendering" with the deep nesting, I know I've had issues with it before.
|
# ? Nov 28, 2015 20:27 |
|
Cock Democracy posted:What's your intention with I think the ultimate goal is to show a list of files of a certain type that are not already owned by another user or something (it's not my code). As I said, though, the part that's freezing is just retrieving the total list of datafiles and their permissions. Cock Democracy posted:but perhaps it sounds like you want all datafiles and their permissions? If that's the case, I agree that it's not such a crazy amount of data that it should take very long. I'd be interested in seeing the model code for Datafile and DatafilePermission. Maybe they are set up wrong somehow. The datafile code is pretty messy, just because it's one of our main models. I can post the header info if you like (i.e. all the belongs_to and has_many lines, as well as the validations, I guess), but there will be a lot of irrelevant crap. Also, just to be clear, the issue isn't that it's slow, it's that it stops completely. I think I let it grind overnight once, and it was still stalled the next morning. The server and console also don't respond to ctrl-c once they try this command, and the Linux process (server or console) doesn't respond to the regular kill command, so it's pretty well and truly frozen, not just taking a long time. necrotic posted:It could be the nested loading (Datafile -> Permissions -> Users) causing issues. What happens if you do the same thing in a script, not a Rails console? It could be an issue "rendering" with the deep nesting, I know I've had issues with it before. I'll try a script version of it on Monday, when I get back to work. However, even just one level of nesting is causing the issue (Datafile -> Permissions), but only on my machine. The last thing I tried before leaving Friday was updating the mysql2 gem, in case I just have a bad version of that. That update, of course, broke everything, so I have to sort that out before I can do anything else. I really don't think it can be an actual rails problem, since it works fine for everyone else's environment (same versions of rails). It also shouldn't be an actual MySQL issue, since the raw query runs okay at a MySQL prompt, so I thought maybe the connector between them was the problem. I also have a different version of MySQL than the test and prod environments have, though mine is more recent. Peristalsis fucked around with this message at 23:05 on Nov 28, 2015 |
# ? Nov 28, 2015 23:03 |
|
Peristalsis posted:I'll try a script version of it on Monday, when I get back to work. However, even just one level of nesting is causing the issue (Datafile -> Permissions), but only on my machine. I have a script called includes_script.rb containing the single line code:
code:
1) When I execute the code by loading the script, no SQL stuff shows on the screen. It just thinks for a moment, then returns true. When I do something that actually freezes the console, it tries to show the SQL command as it dies: code:
code:
Peristalsis fucked around with this message at 17:26 on Nov 30, 2015 |
# ? Nov 30, 2015 17:19 |
|
Try redefining #inspect on the offending classes to something short.
|
# ? Nov 30, 2015 18:35 |
|
Smol posted:Try redefining #inspect on the offending classes to something short. I guess I don't understand this suggestion. What class should have it overridden, and what will the results of doing so tell me?
|
# ? Nov 30, 2015 20:11 |
|
Peristalsis posted:I guess I don't understand this suggestion. What class should have it overridden, and what will the results of doing so tell me? On the Datafile class, so that the console output is less verbose
|
# ? Nov 30, 2015 23:46 |
|
Just add "def inspect; "foo"; end" in DataFile and whatever other AR models you were having troubles with. It sounds like the REPL somehow hangs up when it tries to print the results of inspecting the object graph. Big #inspect messages can be pretty broken especially when something throws a NameError.
|
# ? Nov 30, 2015 23:46 |
|
|
# ? Apr 29, 2024 18:19 |
|
Smol posted:
Exactly what I meant with "It could be an issue "rendering" with the deep nesting". The fact that it runs fine in the script is indicative of this as well.
|
# ? Nov 30, 2015 23:52 |