Merge branch 'master' into global-switchoff

This commit is contained in:
Kim Gardner
2018-05-15 17:55:35 -04:00
committed by GitHub
55 changed files with 530 additions and 352 deletions
+6 -13
View File
@@ -9,7 +9,8 @@ const Action = new Schema(
id: {
type: String,
default: uuid.v4,
unique: true,
unique: 1,
index: 1,
},
action_type: {
type: String,
@@ -19,7 +20,10 @@ const Action = new Schema(
type: String,
enum: ITEM_TYPES,
},
item_id: String,
item_id: {
type: String,
index: 1,
},
user_id: String,
// The element that summaries will additionally group on in addtion to their action_type, item_type, and
@@ -37,15 +41,4 @@ const Action = new Schema(
}
);
// Create an index on the `item_id` field so that queries looking for
// actions based on the item id can resolve faster.
Action.index(
{
item_id: 1,
},
{
background: true,
}
);
module.exports = Action;
+55 -104
View File
@@ -55,12 +55,16 @@ const Comment = new Schema(
type: String,
default: uuid.v4,
unique: true,
index: true,
},
body: {
type: String,
},
body_history: [BodyHistoryItemSchema],
asset_id: String,
asset_id: {
type: String,
index: true,
},
author_id: String,
status_history: [Status],
status: {
@@ -90,7 +94,6 @@ const Comment = new Schema(
// deleted_at stores the date that the given comment was deleted.
deleted_at: {
type: Date,
default: null,
},
// Additional metadata stored on the field.
@@ -110,95 +113,67 @@ const Comment = new Schema(
}
);
// Add the indexes for the id of the comment.
Comment.index(
{
id: 1,
},
{
unique: true,
background: false,
}
);
Comment.index(
{
status: 1,
created_at: 1,
},
{
background: true,
}
);
Comment.index(
{
status: 1,
created_at: 1,
asset_id: 1,
},
{
background: true,
}
);
// Create a sparse index to search across.
Comment.index(
{
created_at: 1,
'action_counts.flag': 1,
status: 1,
},
{
background: true,
sparse: true,
}
);
// Create a sparse index to search across.
Comment.index(
{
'action_counts.flag': 1,
status: 1,
},
{
background: true,
sparse: true,
}
);
// Add an index that is optimized for finding flagged comments.
Comment.index(
{
asset_id: 1,
created_at: 1,
'action_counts.flag': 1,
},
{
background: true,
}
);
// Add an index for the reply sort.
Comment.index(
{
asset_id: 1,
deleted_at: 1,
created_at: -1,
reply_count: -1,
},
{
background: true,
}
{ partialFilterExpression: { deleted_at: null } }
);
// Add an index that is optimized for finding a user's comments.
Comment.index(
{
author_id: 1,
deleted_at: 1,
status: 1,
created_at: -1,
},
{ partialFilterExpression: { deleted_at: null } }
);
Comment.index({
asset_id: 1,
created_at: -1,
});
Comment.index({
asset_id: 1,
created_at: 1,
});
Comment.index({
author_id: 1,
created_at: -1,
});
Comment.index({
asset_id: 1,
status: 1,
});
Comment.index({
asset_id: 1,
parent_id: 1,
reply_count: -1,
created_at: -1,
});
Comment.index({
asset_id: 1,
reply_count: -1,
created_at: -1,
});
Comment.index(
{
'action_counts.flag': 1,
status: 1,
created_at: -1,
},
{
background: true,
partialFilterExpression: {
'action_counts.flag': { $exists: true, $gt: 0 },
deleted_at: null,
},
}
);
@@ -210,34 +185,10 @@ Comment.index(
status: 1,
},
{
background: true,
}
);
// Optimize for tag searches/counts.
Comment.index(
{
'tags.tag.name': 1,
status: 1,
},
{
background: true,
sparse: true,
}
);
// Add an index that is optimized for sorting based on the created_at timestamp
// but also good at locating comments that have a specific asset id.
Comment.index(
{
asset_id: 1,
created_at: 1,
},
{
background: true,
}
);
Comment.virtual('edited').get(function() {
return this.body_history.length > 1;
});
+2
View File
@@ -12,6 +12,8 @@ const Setting = new Schema(
id: {
type: String,
default: '1',
unique: 1,
index: true,
},
moderation: {
type: String,
+19 -28
View File
@@ -58,6 +58,7 @@ const User = new Schema(
default: uuid.v4,
unique: true,
required: true,
index: true,
},
// This is sourced from the social provider or set manually during user setup
@@ -107,6 +108,7 @@ const User = new Schema(
status: {
type: String,
enum: USER_STATUS_USERNAME,
index: true,
},
// History stores the history of username status changes.
@@ -135,6 +137,7 @@ const User = new Schema(
type: Boolean,
required: true,
default: false,
index: true,
},
history: [
{
@@ -226,41 +229,26 @@ User.index(
}
);
User.index(
{
lowercaseUsername: 1,
'profiles.id': 1,
created_at: -1,
},
{
background: true,
}
);
User.index({
lowercaseUsername: 1,
'profiles.id': 1,
created_at: -1,
});
// This query is executed often, to count the number of flagged accounts with
// usernames.
User.index(
{
'action_counts.flag': 1,
'status.username.status': 1,
},
{
background: true,
}
);
User.index({
'action_counts.flag': 1,
'status.username.status': 1,
});
// Sorting users by created at is the default people search.
User.index(
{
created_at: -1,
},
{
background: true,
}
);
User.index({
created_at: -1,
});
/**
* returns true if a commenter is staff
* returns true if a commenter is staff.
*/
User.method('isStaff', function() {
return this.role !== 'COMMENTER';
@@ -330,6 +318,9 @@ User.virtual('hasVerifiedEmail').get(function() {
});
});
/**
* system returns true when the user is a system user.
*/
User.virtual('system')
.get(function() {
return this._system;