Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Changing parent results in never-ending loop for some records #79

Closed
JeanMertz opened this Issue · 1 comment

1 participant

@JeanMertz

I'm having some troubles assigning a record to the root level of the table.

Here is my console output, with the problem at the end:

1.9.3 (main):0 > Page.all
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
| id | published | position | ancestry | ancestry_depth | user_style_id | theme_id | website_id | created_at              | updated_at              | name        | cached_slug |
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
| 3  | true      | 0        | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | vixia       | vixia       |
| 4  | false     | 4194304  | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | immens      | immens      |
| 5  | false     | 6291456  | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | vivre       | vivre       |
| 6  | false     | 0        | 2/5      | 2              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | molenhof    | molenhof    |
| 2  | true      | 2796203  |          | 0              |               | 2        | 1          | 2011-09-27 10:22:57 UTC | 2011-09-27 10:37:54 UTC | projecten   | projecten   |
| 1  | true      | 5592405  |          | 0              |               | 1        | 1          | 2011-09-27 10:22:57 UTC | 2011-09-27 11:31:05 UTC | startpagina | startpagina |
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
6 rows in set
1.9.3 (main):0 > Page.find(1).update_attributes(parent: Page.find(2))
  Page Load (34.3ms)  SELECT "pages".* FROM "pages" WHERE "pages"."id" = $1 LIMIT 1  [["id", 1]]
  Page Load (0.2ms)  SELECT "pages".* FROM "pages" WHERE "pages"."id" = $1 LIMIT 1  [["id", 2]]
   (0.1ms)  BEGIN
  Page Load (0.4ms)  SELECT "pages".* FROM "pages" WHERE (pages.ancestry like '1/%' or pages.ancestry = '1')
   (0.7ms)  UPDATE "pages" SET "ancestry" = '2', "ancestry_depth" = 1, "updated_at" = '2011-09-27 11:41:11.270800' WHERE "pages"."id" = 1
   (0.7ms)  COMMIT
=> true

1.9.3 (main):0 > Page.all
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
| id | published | position | ancestry | ancestry_depth | user_style_id | theme_id | website_id | created_at              | updated_at              | name        | cached_slug |
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
| 3  | true      | 0        | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | vixia       | vixia       |
| 4  | false     | 4194304  | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | immens      | immens      |
| 5  | false     | 6291456  | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | vivre       | vivre       |
| 6  | false     | 0        | 2/5      | 2              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | molenhof    | molenhof    |
| 2  | true      | 2796203  |          | 0              |               | 2        | 1          | 2011-09-27 10:22:57 UTC | 2011-09-27 10:37:54 UTC | projecten   | projecten   |
| 1  | true      | 5592405  | 2        | 1              |               | 1        | 1          | 2011-09-27 10:22:57 UTC | 2011-09-27 11:41:11 UTC | startpagina | startpagina |
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
6 rows in set
1.9.3 (main):0 > 
1.9.3 (main):0 > Page.find(1).update_attributes(parent: nil)
  Page Load (0.5ms)  SELECT "pages".* FROM "pages" WHERE "pages"."id" = $1 LIMIT 1  [["id", 1]]
   (0.2ms)  BEGIN
  Page Load (0.2ms)  SELECT "pages".* FROM "pages" WHERE (pages.ancestry like '2/1/%' or pages.ancestry = '2/1')
   (0.3ms)  UPDATE "pages" SET "ancestry" = NULL, "ancestry_depth" = 0, "updated_at" = '2011-09-27 11:42:35.716529' WHERE "pages"."id" = 1
   (0.6ms)  COMMIT
=> true

1.9.3 (main):0 > Page.all
  Page Load (0.4ms)  SELECT "pages".* FROM "pages" 
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
| id | published | position | ancestry | ancestry_depth | user_style_id | theme_id | website_id | created_at              | updated_at              | name        | cached_slug |
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
| 3  | true      | 0        | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | vixia       | vixia       |
| 4  | false     | 4194304  | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | immens      | immens      |
| 5  | false     | 6291456  | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | vivre       | vivre       |
| 6  | false     | 0        | 2/5      | 2              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 10:22:58 UTC | molenhof    | molenhof    |
| 2  | true      | 2796203  |          | 0              |               | 2        | 1          | 2011-09-27 10:22:57 UTC | 2011-09-27 10:37:54 UTC | projecten   | projecten   |
| 1  | true      | 5592405  |          | 0              |               | 1        | 1          | 2011-09-27 10:22:57 UTC | 2011-09-27 11:42:35 UTC | startpagina | startpagina |
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------------+-------------+
6 rows in set
1.9.3 (main):0 > Page.find(3).update_attributes(parent: nil)
  Page Load (0.5ms)  SELECT "pages".* FROM "pages" WHERE "pages"."id" = $1 LIMIT 1  [["id", 3]]
   (0.2ms)  BEGIN
  Page Load (0.4ms)  SELECT "pages".* FROM "pages" WHERE (pages.ancestry like '2/3/%' or pages.ancestry = '2/3')
^C   (4265.4ms)  UPDATE "pages" SET "ancestry" = NULL, "ancestry_depth" = 0, "updated_at" = '2011-09-27 11:44:06.956251' WHERE "pages"."id" = 3
Interrupt: : UPDATE "pages" SET "ancestry" = NULL, "ancestry_depth" = 0, "updated_at" = '2011-09-27 11:44:06.956251' WHERE "pages"."id" = 3
^Z
[18]+  Stopped                 rails c

The last three lines in the above query are key. Somehow the query gets in some kind of loop or whatever, basically stopping anything from happening after the line:
Page Load (0.4ms) SELECT "pages".* FROM "pages" WHERE (pages.ancestry like '2/3/%' or pages.ancestry = '2/3')

The same thing happens if I try to change its parent to ID: 2

It is only after hitting ^C that the next line shows up (which is the query that is stopping the code):
Interrupt: : UPDATE "pages" SET "ancestry" = NULL, "ancestry_depth" = 0, "updated_at" = '2011-09-27 11:44:06.956251' WHERE "pages"."id" = 3

However, the application is still in some kind of loop at that point, so I can't do anything in the console. Only hitting ^Z exits the console, but nothing has changed in the database the next time I check Page.all again in the console.

The reason I say some kind of loop is because I've been watching the activity monitor and I can't see any of the Ruby processes spiking at all. So it doesn't seem to really be in a never-ending loop, or at least not one that stresses the CPU.

Any clues here? Everything seems to work, except I can't move the record with ID: 3 to parent nil, or to ID: 2 somehow?

This is my model:

class Page < ActiveRecord::Base
  has_ancestry orphan_strategy: :restrict, cache_depth: true
end
@JeanMertz

As always, after posting a problem you usually find the solution yourself.

In this case I noticed a lot of Ruby processes in the activity monitor, they where obviously left behind after hitting ^Z all the time. After closing the terminal and opening a new one, the problem seems to have vanished... for now.

@JeanMertz JeanMertz closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.