MCPcopy
hub / github.com/writefreely/writefreely / GetAllPostsTaggedIDs

Method GetAllPostsTaggedIDs

database.go:1371–1414  ·  view source on GitHub ↗
(c *Collection, tag string, includeFuture bool)

Source from the content-addressed store, hash-verified

1369}
1370
1371func (db *datastore) GetAllPostsTaggedIDs(c *Collection, tag string, includeFuture bool) ([]string, error) {
1372 collID := c.ID
1373
1374 cf := c.NewFormat()
1375 order := "DESC"
1376 if cf.Ascending() {
1377 order = "ASC"
1378 }
1379
1380 timeCondition := ""
1381 if !includeFuture {
1382 timeCondition = "AND created <= " + db.now()
1383 }
1384 var rows *sql.Rows
1385 var err error
1386 if db.driverName == driverSQLite {
1387 rows, err = db.Query("SELECT id FROM posts WHERE collection_id = ? AND LOWER(content) regexp ? "+timeCondition+" ORDER BY created "+order, collID, `.*#`+strings.ToLower(tag)+`\b.*`)
1388 } else {
1389 rows, err = db.Query("SELECT id FROM posts WHERE collection_id = ? AND LOWER(content) RLIKE ? "+timeCondition+" ORDER BY created "+order, collID, "#"+strings.ToLower(tag)+"[[:>:]]")
1390 }
1391 if err != nil {
1392 log.Error("Failed selecting tagged posts: %v", err)
1393 return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve tagged collection posts."}
1394 }
1395 defer rows.Close()
1396
1397 ids := []string{}
1398 for rows.Next() {
1399 var id string
1400 err = rows.Scan(&id)
1401 if err != nil {
1402 log.Error("Failed scanning row: %v", err)
1403 break
1404 }
1405
1406 ids = append(ids, id)
1407 }
1408 err = rows.Err()
1409 if err != nil {
1410 log.Error("Error after Next() on rows: %v", err)
1411 }
1412
1413 return ids, nil
1414}
1415
1416// GetPostsTagged retrieves all posts on the given Collection that contain the
1417// given tag.

Callers

nothing calls this directly

Calls 4

nowMethod · 0.95
NewFormatMethod · 0.80
AscendingMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected