2018-07-17 22:19:24 +00:00
|
|
|
import * as mongo from 'mongodb';
|
|
|
|
import db from '../db/mongodb';
|
|
|
|
|
|
|
|
const Hashtag = db.get<IHashtags>('hashtags');
|
|
|
|
Hashtag.createIndex('tag', { unique: true });
|
2019-02-17 14:41:47 +00:00
|
|
|
Hashtag.createIndex('mentionedUsersCount');
|
|
|
|
Hashtag.createIndex('mentionedLocalUsersCount');
|
2019-02-18 02:47:25 +00:00
|
|
|
Hashtag.createIndex('mentionedRemoteUsersCount');
|
2019-02-17 14:41:47 +00:00
|
|
|
Hashtag.createIndex('attachedUsersCount');
|
|
|
|
Hashtag.createIndex('attachedLocalUsersCount');
|
2019-02-18 02:47:25 +00:00
|
|
|
Hashtag.createIndex('attachedRemoteUsersCount');
|
2018-07-17 22:19:24 +00:00
|
|
|
export default Hashtag;
|
|
|
|
|
2019-02-17 14:41:47 +00:00
|
|
|
// 後方互換性のため
|
|
|
|
Hashtag.findOne({ attachedUserIds: { $exists: false }}).then(h => {
|
|
|
|
if (h != null) {
|
|
|
|
Hashtag.update({}, {
|
|
|
|
$rename: {
|
|
|
|
mentionedUserIdsCount: 'mentionedUsersCount'
|
|
|
|
},
|
|
|
|
$set: {
|
|
|
|
mentionedLocalUserIds: [],
|
|
|
|
mentionedLocalUsersCount: 0,
|
|
|
|
attachedUserIds: [],
|
|
|
|
attachedUsersCount: 0,
|
|
|
|
attachedLocalUserIds: [],
|
|
|
|
attachedLocalUsersCount: 0,
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
multi: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-02-18 02:47:25 +00:00
|
|
|
Hashtag.findOne({ attachedRemoteUserIds: { $exists: false }}).then(h => {
|
|
|
|
if (h != null) {
|
|
|
|
Hashtag.update({}, {
|
|
|
|
$set: {
|
|
|
|
mentionedRemoteUserIds: [],
|
|
|
|
mentionedRemoteUsersCount: 0,
|
|
|
|
attachedRemoteUserIds: [],
|
|
|
|
attachedRemoteUsersCount: 0,
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
multi: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-02-17 14:41:47 +00:00
|
|
|
|
2018-07-17 22:19:24 +00:00
|
|
|
export interface IHashtags {
|
|
|
|
tag: string;
|
|
|
|
mentionedUserIds: mongo.ObjectID[];
|
2019-02-17 14:41:47 +00:00
|
|
|
mentionedUsersCount: number;
|
|
|
|
mentionedLocalUserIds: mongo.ObjectID[];
|
|
|
|
mentionedLocalUsersCount: number;
|
2019-02-18 02:47:25 +00:00
|
|
|
mentionedRemoteUserIds: mongo.ObjectID[];
|
|
|
|
mentionedRemoteUsersCount: number;
|
2019-02-17 14:41:47 +00:00
|
|
|
attachedUserIds: mongo.ObjectID[];
|
|
|
|
attachedUsersCount: number;
|
|
|
|
attachedLocalUserIds: mongo.ObjectID[];
|
|
|
|
attachedLocalUsersCount: number;
|
2019-02-18 02:47:25 +00:00
|
|
|
attachedRemoteUserIds: mongo.ObjectID[];
|
|
|
|
attachedRemoteUsersCount: number;
|
2018-07-17 22:19:24 +00:00
|
|
|
}
|