MCPcopy
hub / github.com/jwngr/sdow / fetch_links_helper

Method fetch_links_helper

sdow/database.py:200–223  ·  view source on GitHub ↗

Helper function which handles duplicate logic for fetch_outgoing_links() and fetch_incoming_links(). Args: page_ids: A list of page IDs whose links to fetch. outcoming_or_incoming_links: String which indicates whether to fetch outgoing ("source_id") or incoming ("target_

(self, page_ids, outcoming_or_incoming_links)

Source from the content-addressed store, hash-verified

198 return self.fetch_links_helper(page_ids, 'incoming_links')
199
200 def fetch_links_helper(self, page_ids, outcoming_or_incoming_links):
201 """Helper function which handles duplicate logic for fetch_outgoing_links() and
202 fetch_incoming_links().
203
204 Args:
205 page_ids: A list of page IDs whose links to fetch.
206 outcoming_or_incoming_links: String which indicates whether to fetch outgoing ("source_id") or
207 incoming ("target_id") links.
208
209 Returns:
210 list(int, int): A cursor of a lists of integer tuples representing links from the list of
211 provided page IDs to other pages.
212 """
213 # Convert the page IDs into a string surrounded by parentheses for insertion into the query
214 # below. The replace() bit is some hackery to handle Python printing a trailing ',' when there
215 # is only one key.
216 page_ids = str(tuple(page_ids)).replace(',)', ')')
217
218 # There is no need to escape the query parameters here since they are never user-defined.
219 query = 'SELECT id, {0} FROM links WHERE id IN {1};'.format(
220 outcoming_or_incoming_links, page_ids)
221 self.sdow_cursor.execute(query)
222
223 return self.sdow_cursor
224
225 def insert_result(self, search):
226 """Inserts a new search result into the searches table.

Callers 2

fetch_outgoing_linksMethod · 0.95
fetch_incoming_linksMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected