Пример #1
0
 public static function batch_activate($user_id, $post_ids)
 {
     $conds = $cond_params = array();
     if ($user_id) {
         $conds[] = "user_id = ?";
         $cond_params[] = $user_id;
     }
     $conds[] = "is_held";
     $conds[] = "id = ?";
     # Tricky: we want posts to show up in the index in the same order they were posted.
     # If we just bump the posts, the index_timestamps will all be the same, and they'll
     # show up in an undefined order.    We don't want to do this in the ORDER BY when
     # searching, because that's too expensive.    Instead, tweak the timestamps slightly:
     # for each post updated, set the index_timestamps 1ms newer than the previous.
     #
     # Returns the number of posts actually activated.
     $count = 0;
     # Original function is kinda confusing...
     # If anyone knows a better way to do this, it'll be welcome.
     sort($post_ids);
     $s = 1;
     $timestamp = strtotime(self::connection()->selectValue("SELECT index_timestamp FROM posts ORDER BY id DESC LIMIT 1"));
     foreach ($post_ids as $id) {
         $timestamp += $s;
         $params = array_merge(array('UPDATE posts SET index_timestamp = ?, is_held = 0 WHERE ' . implode(' AND ', $conds)), array(date('Y-m-d H:i:s', $timestamp)), $cond_params, array($id));
         self::connection()->executeSql($params);
         $count++;
         $s++;
     }
     if ($count > 0) {
         Moebooru\CacheHelper::expire();
     }
     return $count;
 }
Пример #2
0
 public function expire_cache()
 {
     Moebooru\CacheHelper::expire();
 }