Make "order" field an index and use Max aggregate to find next order value.

The "order" field should be a database index for performance reasons. Using the MAX(order) SQL aggregate should also improve performance for larger datasets.