<commit_before>'use strict';
import { Meteor } from 'meteor/meteor';
import { UserStatus } from 'meteor/mizzao:user-status';
import { dbThreads } from '../db/dbThreads';

export const threadId = (process.env.GALAXY_CONTAINER_ID || '') + '!' + process.pid;

Meteor.startup(function() {
  dbThreads.insert({
    _id: threadId,
    doIntervalWork: false,
    refreshTime: new Date(),
    connections: UserStatus.connections.find().count()
  });
  //定期更新thread回報時間與當前連線數量
  Meteor.setInterval(refreshThread, 15000);
});

function refreshThread() {
  //定期更新thread回報時間與當前連線數量
  if (dbThreads.find(threadId).count() > 0) {
    dbThreads.update(threadId, {
      $set: {
        connections: UserStatus.connections.find().count(),
        refreshTime: new Date()
      }
    });
  }
  else {
    dbThreads.insert({
      _id: threadId,
      doIntervalWork: false,
      refreshTime: new Date(),
      connections: UserStatus.connections.find().count()
    });
  }
}
<commit_msg>重用應重複使用的程式碼。<commit_after>'use strict';
import { Meteor } from 'meteor/meteor';
import { UserStatus } from 'meteor/mizzao:user-status';
import { dbThreads } from '../db/dbThreads';

export const threadId = (process.env.GALAXY_CONTAINER_ID || '') + '!' + process.pid;

Meteor.startup(function() {
  refreshThread();
  //定期更新thread回報時間與當前連線數量
  Meteor.setInterval(refreshThread, 15000);
});

function refreshThread() {
  //定期更新thread回報時間與當前連線數量
  if (dbThreads.find(threadId).count() > 0) {
    dbThreads.update(threadId, {
      $set: {
        connections: UserStatus.connections.find().count(),
        refreshTime: new Date()
      }
    });
  }
  else {
    dbThreads.insert({
      _id: threadId,
      doIntervalWork: false,
      refreshTime: new Date(),
      connections: UserStatus.connections.find().count()
    });
  }
}

{'fraction_non_alphanumeric': 0.15196894065446478, 'fraction_numerical': 0.0066555740432612314, 'mean_word_length': 3.4324324324324325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3575723', 'n_tokens_mistral': 670, 'n_tokens_neox': 662, 'n_words': 105}