CoolFace
Apppublic

sanket3280/code-execution

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
CodeHistory.js68 linesDownload Raw Back to models
1const mongoose = require('mongoose');2const Schema = mongoose.Schema;3 4const CodeHistorySchema = new Schema({5  challengeId: {6    type: Schema.Types.ObjectId,7    ref: 'Challenge',8    required: true,9    index: true10  },11  participantId: {12    type: Schema.Types.ObjectId,13    ref: 'User',14    required: true,15    index: true16  },17  problemId: {18    type: Schema.Types.ObjectId,19    ref: 'Problem',20    required: true21  },22  code: {23    type: String,24    required: true25  },26  language: {27    type: String,28    required: true29  },30  changeType: {31    type: String,32    enum: ['typing', 'paste', 'delete', 'snapshot'],33    default: 'typing'34  },35  linesChanged: {36    type: Number,37    default: 038  },39  deltaSize: {40    type: Number,41    default: 042  },43  timestamp: {44    type: Date,45    default: Date.now,46    index: true47  },48  expiresAt: {49    type: Date,50    index: true,51    // Auto-delete after 7 days52    default: () => new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)53  }54});55 56// Compound index for efficient queries57CodeHistorySchema.index({ 58  challengeId: 1, 59  participantId: 1, 60  problemId: 1, 61  timestamp: -1 62});63 64// TTL index for automatic cleanup65CodeHistorySchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });66 67module.exports = mongoose.model('CodeHistory', CodeHistorySchema);68