mirror of
https://github.com/documize/community.git
synced 2025-07-21 14:19:43 +02:00
Make search re-indexing multi-tenant aware
Makes things easier when having to reindex in multi-tenant deployments.
This commit is contained in:
parent
85b3f6e8ee
commit
8eb930d281
7 changed files with 731 additions and 684 deletions
|
@ -28,7 +28,7 @@ type Store struct {
|
|||
store.AttachmentStorer
|
||||
}
|
||||
|
||||
// Add inserts the given record into the database attachement table.
|
||||
// Add inserts the given record into the database attachment table.
|
||||
func (s Store) Add(ctx domain.RequestContext, a attachment.Attachment) (err error) {
|
||||
a.OrgID = ctx.OrgID
|
||||
a.Created = time.Now().UTC()
|
||||
|
@ -64,7 +64,7 @@ func (s Store) GetAttachment(ctx domain.RequestContext, orgID, attachmentID stri
|
|||
return
|
||||
}
|
||||
|
||||
// GetAttachments returns a slice containing the attachement records (excluding their data) for document docID, ordered by filename.
|
||||
// GetAttachments returns a slice containing the attachment records (excluding their data) for document docID, ordered by filename.
|
||||
func (s Store) GetAttachments(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Select(&a, s.Bind(`
|
||||
SELECT id, c_refid AS refid,
|
||||
|
@ -72,7 +72,7 @@ func (s Store) GetAttachments(ctx domain.RequestContext, docID string) (a []atta
|
|||
c_filename AS filename, c_extension AS extension,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_attachment
|
||||
WHERE c_orgid=? and c_docid=?
|
||||
WHERE c_orgid=? AND c_docid=?
|
||||
ORDER BY c_filename`),
|
||||
ctx.OrgID, docID)
|
||||
|
||||
|
@ -88,7 +88,7 @@ func (s Store) GetAttachments(ctx domain.RequestContext, docID string) (a []atta
|
|||
return
|
||||
}
|
||||
|
||||
// GetAttachmentsWithData returns a slice containing the attachement records (including their data) for document docID, ordered by filename.
|
||||
// GetAttachmentsWithData returns a slice containing the attachment records (including their data) for document docID, ordered by filename.
|
||||
func (s Store) GetAttachmentsWithData(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Select(&a, s.Bind(`
|
||||
SELECT id, c_refid AS refid,
|
||||
|
|
|
@ -57,7 +57,7 @@ func (s Store) Get(ctx domain.RequestContext, id string) (document doc.Document,
|
|||
c_lifecycle AS lifecycle, c_versioned AS versioned, c_versionid AS versionid,
|
||||
c_versionorder AS versionorder, c_groupid AS groupid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc
|
||||
WHERE c_orgid=? and c_refid=?`),
|
||||
WHERE c_orgid=? AND c_refid=?`),
|
||||
ctx.OrgID, id)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -204,7 +204,7 @@ func (h *Handler) Reindex(w http.ResponseWriter, r *http.Request) {
|
|||
func (h *Handler) rebuildSearchIndex(ctx domain.RequestContext) {
|
||||
method := "meta.rebuildSearchIndex"
|
||||
|
||||
docs, err := h.Store.Meta.GetDocumentsID(ctx)
|
||||
docs, err := h.Store.Meta.Documents(ctx)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
|
@ -215,23 +215,23 @@ func (h *Handler) rebuildSearchIndex(ctx domain.RequestContext) {
|
|||
for i := range docs {
|
||||
d := docs[i]
|
||||
|
||||
doc, err := h.Store.Document.Get(ctx, d)
|
||||
dc, err := h.Store.Meta.Document(ctx, d)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
// continue
|
||||
}
|
||||
at, err := h.Store.Attachment.GetAttachments(ctx, d)
|
||||
at, err := h.Store.Meta.Attachments(ctx, d)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
// continue
|
||||
}
|
||||
|
||||
h.Indexer.IndexDocument(ctx, doc, at)
|
||||
h.Indexer.IndexDocument(ctx, dc, at)
|
||||
|
||||
pages, err := h.Store.Meta.GetDocumentPages(ctx, d)
|
||||
pages, err := h.Store.Meta.Pages(ctx, d)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
// continue
|
||||
}
|
||||
|
||||
for j := range pages {
|
||||
|
|
|
@ -13,9 +13,11 @@ package meta
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/documize/community/model/doc"
|
||||
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/attachment"
|
||||
"github.com/documize/community/model/page"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -26,9 +28,9 @@ type Store struct {
|
|||
store.MetaStorer
|
||||
}
|
||||
|
||||
// GetDocumentsID returns every document ID value stored.
|
||||
// Documents returns every document ID value stored.
|
||||
// The query runs at the instance level across all tenants.
|
||||
func (s Store) GetDocumentsID(ctx domain.RequestContext) (documents []string, err error) {
|
||||
func (s Store) Documents(ctx domain.RequestContext) (documents []string, err error) {
|
||||
err = s.Runtime.Db.Select(&documents, `SELECT c_refid FROM dmz_doc WHERE c_lifecycle=1`)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
|
@ -42,8 +44,27 @@ func (s Store) GetDocumentsID(ctx domain.RequestContext) (documents []string, er
|
|||
return
|
||||
}
|
||||
|
||||
// GetDocumentPages returns a slice containing all published page records for a given documentID, in presentation sequence.
|
||||
func (s Store) GetDocumentPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
|
||||
// Document fetches the document record with the given id fromt the document table and audits that it has been got.
|
||||
func (s Store) Document(ctx domain.RequestContext, id string) (document doc.Document, err error) {
|
||||
err = s.Runtime.Db.Get(&document, s.Bind(`
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_spaceid AS spaceid, c_userid AS userid,
|
||||
c_job AS job, c_location AS location, c_name AS name, c_desc AS excerpt, c_slug AS slug,
|
||||
c_tags AS tags, c_template AS template, c_protection AS protection, c_approval AS approval,
|
||||
c_lifecycle AS lifecycle, c_versioned AS versioned, c_versionid AS versionid,
|
||||
c_versionorder AS versionorder, c_groupid AS groupid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc
|
||||
WHERE c_refid=?`),
|
||||
id)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute select document")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Pages returns a slice containing all published page records for a given documentID, in presentation sequence.
|
||||
func (s Store) Pages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
|
||||
err = s.Runtime.Db.Select(&p, s.Bind(`
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid,
|
||||
c_userid AS userid, c_contenttype AS contenttype,
|
||||
|
@ -65,6 +86,30 @@ func (s Store) GetDocumentPages(ctx domain.RequestContext, documentID string) (p
|
|||
return
|
||||
}
|
||||
|
||||
// Attachments returns a slice containing the attachment records (excluding their data) for document docID, ordered by filename.
|
||||
func (s Store) Attachments(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error) {
|
||||
err = s.Runtime.Db.Select(&a, s.Bind(`
|
||||
SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_docid AS documentid, c_job AS job, c_fileid AS fileid,
|
||||
c_filename AS filename, c_extension AS extension,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_attachment
|
||||
WHERE c_docid=?
|
||||
ORDER BY c_filename`),
|
||||
docID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
a = []attachment.Attachment{}
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute select attachments")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// SearchIndexCount returns the numnber of index entries.
|
||||
func (s Store) SearchIndexCount(ctx domain.RequestContext) (c int, err error) {
|
||||
row := s.Runtime.Db.QueryRow("SELECT count(*) FROM dmz_search")
|
||||
|
|
|
@ -290,7 +290,9 @@ type GroupStorer interface {
|
|||
|
||||
// MetaStorer provide specialist methods for global administrators.
|
||||
type MetaStorer interface {
|
||||
GetDocumentsID(ctx domain.RequestContext) (documents []string, err error)
|
||||
GetDocumentPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error)
|
||||
Documents(ctx domain.RequestContext) (documents []string, err error)
|
||||
Document(ctx domain.RequestContext, documentID string) (d doc.Document, err error)
|
||||
Pages(ctx domain.RequestContext, documentID string) (p []page.Page, err error)
|
||||
Attachments(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error)
|
||||
SearchIndexCount(ctx domain.RequestContext) (c int, err error)
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func main() {
|
|||
rt.Product.Major = "1"
|
||||
rt.Product.Minor = "71"
|
||||
rt.Product.Patch = "0"
|
||||
rt.Product.Revision = 181005170824
|
||||
rt.Product.Revision = 181006150624
|
||||
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
|
||||
rt.Product.Edition = "Community"
|
||||
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)
|
||||
|
|
1328
embed/bindata.go
1328
embed/bindata.go
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue