Commit 85249a9f authored by Armin Felder's avatar Armin Felder
Browse files

improved startup time

parent 5948f653
......@@ -143,7 +143,7 @@ QVariant ChannelModel::data( const QModelIndex &index, int role ) const
bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel )
{
if ( !channel.isNull() && channel->getRoomId() != "" && !duplicateCheck.contains( channel->getRoomId() ) ) {
//connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::unreadMessagesChanged, this, &ChannelModel::onUnreadMessageChanged, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::dataChanged, this, &ChannelModel::onDataChanged, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::channelDeleted, this, &ChannelModel::onDeleted, Qt::UniqueConnection );
......@@ -167,7 +167,9 @@ bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel
bool ChannelModel::addChannelsSlot(const QVector<QSharedPointer<RocketChatChannel> > &pChannels)
{
beginResetModel();
// beginResetModel();
int from =-1;
int to = -1;
for(const auto &channel: pChannels){
if ( !channel.isNull() && channel->getRoomId() != "" && !duplicateCheck.contains( channel->getRoomId() ) ) {
//connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
......@@ -176,10 +178,22 @@ bool ChannelModel::addChannelsSlot(const QVector<QSharedPointer<RocketChatChanne
connect( channel.data(), &RocketChatChannel::channelDeleted, this, &ChannelModel::onDeleted, Qt::UniqueConnection );
connect(channel.data(), &RocketChatChannel::updatedChanged, this, &ChannelModel::onChannelOrderChanged);
duplicateCheck.insert( channel->getRoomId() );
channelList.insertSort( channel );
auto index = channelList.insertSort( channel );
if(from == -1){
from = index;
to = index;
}
if(index<from){
from = index;
}else if(index>to){
to = index;
}
}
}
endResetModel();
beginInsertRows( QModelIndex(), from, to );
endInsertRows();
// endResetModel();
return true;
}
......@@ -296,6 +310,9 @@ void ChannelModel::onDeleted( const QString &pId, bool deleted )
void ChannelModel::onChannelOrderChanged(const QString &pId, qint64 pTimestamp)
{
static int counter = 0;
counter++;
qDebug() << counter;
beginResetModel();
channelList.reOrder();
endResetModel();
......
......@@ -35,8 +35,13 @@ int SortedVector<T>::insertSort( const QSharedPointer<T> &pointer )
return ( *first ) > ( *second );
} );
row = std::distance(this->begin(), elementSmallerThanNew);
this->insert( elementSmallerThanNew, pointer );
row = elementSmallerThanNew - this->begin();
if(row <0 || row>1000){
qDebug()<<elementSmallerThanNew;
qDebug()<<"error";
}
}
return row;
......
......@@ -25,9 +25,18 @@
#include <QVector>
#include <QSharedPointer>
#include <QMutex>
struct SortedVectorProperties
{
enum class sortOrder{
asc,
dsc
};
};
template<typename T> class SortedVector : public QVector<QSharedPointer<T>>
{
public:
int insertSort( const QSharedPointer<T> & );
int findInsertPosition( const QSharedPointer<T> & ) const;
int findPosition( const QSharedPointer<T> & ) const;
......
......@@ -371,9 +371,9 @@ qint64 RocketChatChannel::getUpdatedAt() const
void RocketChatChannel::setUpdatedAt( const qint64 &updatedAt )
{
//skip signal the first time
if(mUpdatedAt != updatedAt){
if(mUpdatedAt != -1){
emit updatedChanged(mRoomId,mUpdatedAt);
if(mUpdatedAt != updatedAt && updatedAt != -1){
if(mUpdatedAt != -1 ){
emit updatedChanged(mRoomId,updatedAt);
}
mUpdatedAt = updatedAt;
}
......
......@@ -112,8 +112,8 @@ QVector<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processCha
qint64 updatedAt = -1;
if ( currentChannelObject.contains( QStringLiteral( "_updatedAt" ) ) ) {
auto updatedObj = currentChannelObject[QStringLiteral( "_updatedAt" )].toObject();
if ( currentChannelObject.contains( QStringLiteral( "ls" ) ) ) {
auto updatedObj = currentChannelObject[QStringLiteral( "ls" )].toObject();
updatedAt = static_cast<qint64>( updatedObj[QStringLiteral( "$date" )].toDouble() );
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment