fetch associated post if it hasn't been fetched before, or if the incorrect post is cached.
181093
private function updateFromPostCache(Comment $comment, $c)
    {
        if ($comment->postId == null)
        {
            return;
        }
        if ($this->postCache == null || $this->postCache['ID'] != $comment->postId)
        {
            $this->postCache = $this->adminApi->getPost($comment->postId);
        }

        $comment->date = $this->getMetaKeyValue($this->postCache, "linkoscope_created_$comment->id") ?: $c['date'];
        $comment->score =
            $this->getMetaKeyValue($this->postCache, "linkoscope_score_$comment->id") ?: strtotime($c['date']);
    }
1115344
def get(self, key):
        """"""
        query = self._conn.execute("SELECT * FROM cache WHERE key=?", (key,))
        rec = query.fetchone()
        if rec is None:
            return None
        rec = dict(zip(self._columns, rec))

        if self.check_last_modified:
            if rec['modified'] is None:
                return None  # no last modified header present, so redownload

            head_resp = requests.head(key)
            new_lm = head_resp.headers.get('last-modified', None)
            if rec['modified'] != new_lm:
                return None

        resp = requests.Response()
        resp._content = rec['data']
        resp.status_code = rec['status']
        resp.encoding = rec['encoding']
        resp.headers = json.loads(rec['headers'])
        resp.url = key
        return resp
85798
function (model) {
            //if we have them return them;
            if (this.associationLoaded(model)) {
                var assoc = this.getAssociation(model);
                return this.isEager() ? assoc : when(assoc);
            } else if (model.isNew) {
                return null;
            } else {
                return this.fetch(model);
            }
        }
864606
def fetch(self, endpoint, data = None):
        
        payload = {
            "lastServerChangeId": "-1",
            "csrf": self.__csrf,
            "apiClient": "WEB"
        }
        if data is not None:
            payload.update(data)

        return self.post(endpoint, payload)
1207259
private void fetchIfNeeded(long remainingBytes)
  {
    if ((fetchFutures.isEmpty() || fetchFutures.peekLast().isDone())
        && remainingBytes <= prefetchConfig.getPrefetchTriggerBytes()) {
      Future<Void> fetchFuture = fetchExecutor.submit(() -> {
        fetch();
        return null;
      });
      fetchFutures.add(fetchFuture);
    }
  }
460961
def ensure_post
      post_id = params[:post_id] || params[:id]
      board_id = params[:board_id]
      result = has_post_access(board_id, post_id)
      status = result[:status]
      @post = result[:post]
      head status if status != :ok
    end
531029
def user(id)
      if id
        cached_user = users.detect {|u| u[:id] == id }
        user = cached_user || fetch_user(id)
        self.users << user
        user
      end
    end
1137874
function onFetching(model, columns, options) {
        if (options.forUpdate && options.transacting) {
            options.query.forUpdate();
        }
    }
533095
function nextPostHook(res) {
                    response = checkResponse(res, response);

                    if (currentPost + 1 < totalPost && self.__hooksEnabled !== false) {
                        currentPost += 1;

                        // Reference to current post hook
                        const currPost = posts[currentPost];
                        const hookMethod = currPost.displayName || currPost.name;
                        scope = getScope(self, name, res, hookMethod, 'post');

                        // Recursively call all the "post" hooks
                        return currPost.call(scope, response).then(nextPostHook, postHookErrorHandler);
                    }

                    /**
                     * All "post" hook process done.
                     * If the response has an "__override" property it will be our response
                     */
                    if (is.object(response) && {}.hasOwnProperty.call(response, '__override')) {
                        response = response.__override;
                    }

                    return resolveFn(response);
                }
684277
def update(self, force=False):
        

        # The thread has already 404'ed, this function shouldn't do anything anymore.
        if self.is_404 and not force:
            return 0

        if self._last_modified:
            headers = {'If-Modified-Since': self._last_modified}
        else:
            headers = None

        # random connection errors, just return 0 and try again later
        try:
            res = self._board._requests_session.get(self._api_url, headers=headers)
        except:
            # try again later
            return 0

        # 304 Not Modified, no new posts.
        if res.status_code == 304:
            return 0

        # 404 Not Found, thread died.
        elif res.status_code == 404:
            self.is_404 = True
            # remove post from cache, because it's gone.
            self._board._thread_cache.pop(self.id, None)
            return 0

        elif res.status_code == 200:
            # If we somehow 404'ed, we should put ourself back in the cache.
            if self.is_404:
                self.is_404 = False
                self._board._thread_cache[self.id] = self

            # Remove
            self.want_update = False
            self.omitted_images = 0
            self.omitted_posts = 0

            self._last_modified = res.headers['Last-Modified']
            posts = res.json()['posts']

            original_post_count = len(self.replies)
            self.topic = Post(self, posts[0])

            if self.last_reply_id and not force:
                self.replies.extend(Post(self, p) for p in posts if p['no'] > self.last_reply_id)
            else:
                self.replies[:] = [Post(self, p) for p in posts[1:]]

            new_post_count = len(self.replies)
            post_count_delta = new_post_count - original_post_count
            if not post_count_delta:
                return 0

            self.last_reply_id = self.replies[-1].post_number

            return post_count_delta

        else:
            res.raise_for_status()
1049498
def fetchUnseen(self):
        
        j = self._post(
            self.req_url.UNSEEN_THREADS, None, fix_request=True, as_json=True
        )

        payload = j["payload"]["unseen_thread_fbids"][0]
        return payload["thread_fbids"] + payload["other_user_fbids"]
537237
def has_item(self, url):
        

        _hash = self.build_hash(url)
        self.execute('BEGIN')
        self.execute('''
            SELECT id
            FROM cache
            WHERE id = x%s
            LIMIT 1
        ''', (_hash,))
        row = self.cursor.fetchone()
        self.execute('COMMIT')
        return True if row else False
926186
def _did_fetch(self, connection):
        

        self.current_connection = connection
        response = connection.response
        should_commit = 'commit' not in connection.user_info or connection.user_info['commit']

        if connection.response.status_code >= 400 and BambouConfig._should_raise_bambou_http_error:
            raise BambouHTTPError(connection=connection)

        if response.status_code != 200:

            if should_commit:
                self.current_total_count = 0
                self.current_page = 0
                self.current_ordered_by = ''

            return self._send_content(content=None, connection=connection)

        results = response.data
        fetched_objects = list()
        current_ids = list()

        if should_commit:
            if 'X-Nuage-Count' in response.headers and response.headers['X-Nuage-Count']:
                self.current_total_count = int(response.headers['X-Nuage-Count'])

            if 'X-Nuage-Page' in response.headers and response.headers['X-Nuage-Page']:
                self.current_page = int(response.headers['X-Nuage-Page'])

            if 'X-Nuage-OrderBy' in response.headers and response.headers['X-Nuage-OrderBy']:
                self.current_ordered_by = response.headers['X-Nuage-OrderBy']

        if results:
            for result in results:
                nurest_object = self.new()
                nurest_object.from_dict(result)
                nurest_object.parent = self.parent_object

                fetched_objects.append(nurest_object)

                if not should_commit:
                    continue

                current_ids.append(nurest_object.id)

                if nurest_object in self:
                    idx = self.index(nurest_object)
                    current_object = self[idx]
                    current_object.from_dict(nurest_object.to_dict())
                else:
                    self.append(nurest_object)

            if should_commit:
                for obj in self:
                    if obj.id not in current_ids:
                        self.remove(obj)

        return self._send_content(content=fetched_objects, connection=connection)
808572
def query_by_post(postid):
        '''
        
        '''
        return TabReply.select().where(
            TabReply.post_id == postid
        ).order_by(TabReply.timestamp.desc())
231552
def refresh(self):
        
        resp = self._imgur._send_request(self._INFO_URL)
        self._populate(resp)
        self._has_fetched = True
568870
public function fetch() {

        $response = $this->get_response();
        $this->validate_response($response);
        $this->store_response($response);

        // We need to reset plugin manager's caches - the currently existing
        // singleton is not aware of eventually available updates we just fetched.
        \core_plugin_manager::reset_caches();
    }
1005028
def check_exists(subreddit):
    """"""
    req = get('http://www.reddit.com/r/%s/about.json' % subreddit, headers={'User-Agent': 'CslBot/1.0'})
    if req.json().get('kind') == 'Listing':
        # no subreddit exists, search results page is shown
        return False
    return req.status_code == 200