Пример #1
0
Sync.fetchHome = function(options, callback) {
  options = options || {};

  api.multiquery(buildMultiquery(
    'WHERE filter_key IN ("others")' +
    (options.after ? ' AND created_time < ' + options.after : '') +
    ' LIMIT ' + (options.limit || 25) +
    (options.offset ? ' OFFSET ' + options.offset : '')
  ), function(r) {
    var posts = Sync.createAndCacheModels(
      'all',
      r.posts,
      !options.after && !options.offset);
    posts = posts.sort(function(a, b) {
      return b.order - a.order;
    });
    require('./pageSync').createAndCacheModels('min', r.pages, true);
    require('./userSync').createAndCacheModels('min', r.users, true);
    if (!options.after && !options.offset) {
      Base.addToCache({
        id: 'request:home',
        post_ids: posts.map(function(post) { return post.post_id; })
      }, true);
    }
    callback(posts);
  });
};
Пример #2
0
Sync.fetchPost = function(id, callback) {
  api.multiquery(
    buildMultiquery('WHERE post_id = "' + id + '"'),
    function(r) {
    var posts = Sync.createAndCacheModels('all', r.posts, true);
    require('./pageSync').createAndCacheModels('min', r.pages, true);
    require('./userSync').createAndCacheModels('min', r.users, true);
    callback(posts[0]);
  });
};
Пример #3
0
Sync.fetchUser = function(id, callback) {
  api.multiquery({
    user: Sync.buildSELECT('all') + ' WHERE uid = "' + id + '"',
    other: Sync.buildSELECT('min') +
      ' WHERE uid IN (SELECT significant_other_id FROM #user)'
  }, function(r) {
      var users = Sync.createAndCacheModels('all', r.user, true);
      Sync.createAndCacheModels('min', r.other, true);
      callback(users[0]);
  });
};
Пример #4
0
Sync.fetchFriends = function(callback) {
  api.multiquery({
    users: Sync.buildSELECT('min') +
      ' WHERE uid in (SELECT uid2 FROM #ids)',
    ids: 'SELECT uid2 FROM friend WHERE uid1 = me()'
  }, function(r) {
    var users = Sync.createAndCacheModels('min', r.users, true);
    Base.addToCache({ id: 'request:friends', ids: r.users.map(function(u) {
      return u.uid;
    }) }, true);

    callback(users);
  });
};