In a couple of threads there was a discussion on what was best to store messages in a database like
. One of the threads said that the messages should be given a thread id and also have the parent child scheme implemented. The thread id is for fast retrieval and then the messages be sorted out by thread in the program so as not to put stress on the database. The other way is basically to recursively query the database for the children of a parent. Get the parent message and then query for its children and then query for their children ad infinitum and due to the recursion unraveling at the end the messages should be in the correct order.
I've tried to figure out how to sort out the messages without using a recursive way and by retrieveing the messages by thread id and then sorting them to get the correct order for the threads. However the answer eludes me. Is there a way to use
sort to get the messages in the correct order for threading?
my $testarray = [
{ messageId => 1,
parent => 1 },
{ messageId => 2,
parent => 1 },
{ messageId => 3,
parent => 1 },
{ messageId => 4,
parent => 2 },
{ messageId => 5,
parent => 3 },
{ messageId => 6,
parent => 2 },
{ messageId => 7,
parent => 4 }
];
What I'm trying to get from
messageId parent
1 1
2 1
3 1
4 2
5 3
6 2
7 4
to
1 1
2 1
4 2
7 4
6 2
3 1
5 3
Can anyone offer a nudge in the right direction for this please?
My thanks for helping me keep my hair,
BMaximus