Esempio n. 1
0
File: db.js Progetto: epochtalk/core
  return new Promise(function(fulfill, reject) {
    var entries = [ threadId ];
    var sorter = function(entry) { entries.push(entry); };
    var handler = function() {
      if (endIndex) { entries.pop(); }
      return fulfill(entries);
    };

    // query key
    var startKey = threadOrderPrefix + sep + boardId + sep + 'order' + sep;
    var endKey = startKey;
    startKey += encodeIntHex(1);
    if (endIndex) { endKey += encodeIntHex(endIndex) + '\xff'; }
    else { endKey += '\xff'; }
    var queryOptions = {
      gte: startKey,
      lte: endKey
    };

    db.indexes.createValueStream(queryOptions)
    .on('data', sorter)
    .on('error', reject)
    .on('close', handler)
    .on('end', handler);
  })
Esempio n. 2
0
File: db.js Progetto: epochtalk/core
  return new Promise(function(fulfill, reject) {
    var postIds = [];
    var sorter = function(value) { postIds.push(value); };
    var handler = function() { fulfill(postIds); };

    // query vars
    var limit = opts.limit ? Number(opts.limit) : 10;
    var page = opts.page ? Math.abs(Number(opts.page)) : 1;

    // query key
    var postOrderPrefix = config.posts.indexPrefix;
    var sep = config.sep;
    var startKey = postOrderPrefix + sep + threadId + sep;
    var endKey = startKey + '\xff';

    // query start value
    var pageStart = limit * page - (limit - 1);
    pageStart = encodeIntHex(pageStart);
    startKey += pageStart;

    var queryOptions = {
      limit: limit,
      gte: startKey,
      lte: endKey
    };
    // query for all posts fir this threadId
    db.indexes.createValueStream(queryOptions)
    .on('data', sorter)
    .on('error', reject)
    .on('close', handler)
    .on('end', handler);
  })
Esempio n. 3
0
File: db.js Progetto: epochtalk/core
  .then(function() {
    // remove last value
    if (!lastIndex) { lastIndex = startIndex; }
    lastIndex = Number(lastIndex);

    // delete last index position
    var key = postOrderStarter + encodeIntHex(lastIndex);
    db.indexes.delAsync(key);
  });
Esempio n. 4
0
 schema.statics.ensureAllManuallyDefinedSchemaIndexes = function () {
     for (var indexDescriptor in domainDescriptor.indexes) {
         if (domainDescriptor.indexes.hasOwnProperty(indexDescriptor)) {
             schema.index(domainDescriptor.indexes[indexDescriptor]);
         }
     }
     _this.connection.model(domainName, schema).ensureIndexes(function (err) {
         if (err) log.error(err);
     });
 };
Esempio n. 5
0
File: db.js Progetto: epochtalk/core
 .then(function() {
   // old thread index
   var oldBoardThreadKey = Thread.boardThreadKey(thread.id, thread.board_id, oldTimestamp);
   // add new thread index value
   var newBoardThreadKey = Thread.boardThreadKey(thread.id, thread.board_id, post.created_at);
   var indexBatch = [
     { type: 'del', key: oldBoardThreadKey },
     { type: 'put', key: newBoardThreadKey, value: post.thread_id }
   ];
   return db.indexes.batchAsync(indexBatch)
   .then(function() { syncThreadOrder(thread); });
 });
Esempio n. 6
0
File: db.js Progetto: epochtalk/core
    return Promise.each(entries, function(entry) {
      var key = entry.key;
      var value = entry.value;

      // find index from key
      var currentIndex = key.replace(postOrderStarter, '');
      lastIndex = Number(currentIndex);
      var newIndex = lastIndex - 1;

      // handle metadata
      var metadataKey = Post.postOrderKey(value.id);
      db.metadata.putAsync(metadataKey, newIndex);

      // handle index
      var postOrderKey = postOrderStarter + encodeIntHex(newIndex);
      db.indexes.putAsync(postOrderKey, value);
    });
Esempio n. 7
0
File: db.js Progetto: epochtalk/core
  return new Promise(function(fulfill, reject) {
    var entries = [];
    var sorter = function(entry) { entries.push(entry); };
    var handler = function() { fulfill(entries); };

    // query key
    var startKey = postOrderStarter;
    var endKey = startKey + '\xff';
    startKey += encodeIntHex(startIndex + 1);
    var queryOptions = {
      gte: startKey,
      lte: endKey
    };
    // query for all posts fir this threadId
    db.indexes.createReadStream(queryOptions)
    .on('data', sorter)
    .on('error', reject)
    .on('close', handler)
    .on('end', handler);
  })
Esempio n. 8
0
File: db.js Progetto: epochtalk/core
 .then(function() { return db.indexes.putAsync(key, entry); });
Esempio n. 9
0
File: db.js Progetto: epochtalk/core
 .then(function() { // threadPostOrder
   var key = Post.threadPostOrderKey(post.thread_id, postCount);
   return db.indexes.putAsync(key, post.id);
 })