开发者

Database integrity problem while sorting pages

I have almost finished building my cms with drag and drop page sorting and heirarchy editing.

Here is my pages table in my db.

CREATE TABLE `pages` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `metatitle` varchar(255) DEFAULT NULL,
 `metadesc` text,
 `metakw` varchar(255) DEFAULT NULL,
 `create_time` datetime DEFAULT NULL,
 `update_time` datetime DEFAULT NULL,
 `name` varchar(255) DEFAULT NULL,
 `url` va开发者_如何学编程rchar(255) DEFAULT NULL,
 `parent` int(11) DEFAULT NULL,
 `active` tinyint(1) DEFAULT NULL,
 `sort` int(11) DEFAULT NULL,
 `nofollow` tinyint(1) DEFAULT NULL,
 `deletable` tinyint(1) DEFAULT NULL,
 `navshow` tinyint(1) DEFAULT NULL,
 `type` enum('basic','dynamic','virtual') DEFAULT NULL COMMENT 'basic: only contains basic content\ndynamic: contains both dynamic and basic content\nvirtual: redirects to another page',
 `virtual_redirect` int(11) DEFAULT NULL,
 `route` varchar(255) DEFAULT NULL,
 `dynamic_desc` varchar(255) DEFAULT NULL,
 `content1` blob,
 `content2` blob,
 PRIMARY KEY (`id`),
 UNIQUE KEY `url_UNIQUE` (`url`),
 UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1

As you can see from parent field, I'm using the adjacency list model for creating my page heirarchy.

Say I had this page structure...

|-Page 1
| |-Page 3
| |-Page 2
| |-Page 4
| |-Page 5
|-Page 6

If I moved page 3 up a level the structure would now look like this...

|-Page 1
| |-Page 2
| |-Page 4
| |-Page 5
|-Page 3
|-Page 6

Here's my problem.

The above example involves a fairly substantial number of query's ( for such a small tree). I have to change the sort numbers of pages 2-6 and the parent of page 3. That's 7 querys.

What i'm experiencing is that the moving operation produces different results each time I use it. ie: sometimes it works perfectly, other times the sort numbers don't update properly.

It's as though the database craps out on a few of the queries and pretty soon the consistency of the database is ruined.

I'm not sure whether it's because there are too many queries or some other factor. But I'm finding it very difficult to diagnose.

Any ideas what the problem might be?

Cheers Tom


I advise you to read how to manage hierarchical data in database

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜